X-Git-Url: http://www.git.cypherpunks.ru/?p=govpn.git;a=blobdiff_plain;f=src%2Fcypherpunks.ru%2Fgovpn%2Fidentity.go;h=262bca658be887c4b779dacef6b503ecbaf66b96;hp=89b12ab5cb118687415ef05c0cbbed79cbd10a9c;hb=f47fff1e42f75b736e7067ec06c2e81394833d46;hpb=588499ac2eedea258c304fca647509c7b587d7e8 diff --git a/src/cypherpunks.ru/govpn/identity.go b/src/cypherpunks.ru/govpn/identity.go index 89b12ab..262bca6 100644 --- a/src/cypherpunks.ru/govpn/identity.go +++ b/src/cypherpunks.ru/govpn/identity.go @@ -34,13 +34,13 @@ const ( IDSize = 128 / 8 ) -type PeerId [IDSize]byte +type PeerID [IDSize]byte -func (id PeerId) String() string { +func (id PeerID) String() string { return base64.RawStdEncoding.EncodeToString(id[:]) } -func (id PeerId) MarshalJSON() ([]byte, error) { +func (id PeerID) MarshalJSON() ([]byte, error) { return []byte(`"` + id.String() + `"`), nil } @@ -51,18 +51,18 @@ type MACAndTimeSync struct { } type MACCache struct { - cache map[PeerId]*MACAndTimeSync + cache map[PeerID]*MACAndTimeSync l sync.RWMutex } func NewMACCache() *MACCache { - return &MACCache{cache: make(map[PeerId]*MACAndTimeSync)} + return &MACCache{cache: make(map[PeerID]*MACAndTimeSync)} } // Remove disappeared keys, add missing ones with initialized MACs. -func (mc *MACCache) Update(peers *map[PeerId]*PeerConf) { +func (mc *MACCache) Update(peers *map[PeerID]*PeerConf) { mc.l.Lock() - for pid, _ := range mc.cache { + for pid := range mc.cache { if _, exists := (*peers)[pid]; !exists { log.Println("Cleaning key:", pid) delete(mc.cache, pid) @@ -101,7 +101,7 @@ func AddTimeSync(ts int, data []byte) { // Try to find peer's identity (that equals to MAC) // by taking first blocksize sized bytes from data at the beginning // as plaintext and last bytes as cyphertext. -func (mc *MACCache) Find(data []byte) *PeerId { +func (mc *MACCache) Find(data []byte) *PeerID { if len(data) < 8*2 { return nil } @@ -117,7 +117,7 @@ func (mc *MACCache) Find(data []byte) *PeerId { mt.mac.Sum(sum[:0]) mt.l.Unlock() if subtle.ConstantTimeCompare(sum[len(sum)-8:], data[len(data)-8:]) == 1 { - ppid := PeerId(pid) + ppid := PeerID(pid) mc.l.RUnlock() return &ppid }