Commit 0244bad5 authored by Petar Radovic's avatar Petar Radovic Committed by GitHub

swarm.Address - ByteString() (#16)

Use ByteString from swarm.Address
parent e4ffe287
......@@ -54,7 +54,7 @@ func (r *peerRegistry) Disconnected(_ network.Network, c network.Conn) {
overlay := r.overlays[peerID]
delete(r.overlays, peerID)
delete(r.underlays, encodeunderlaysKey(overlay))
delete(r.underlays, overlay.ByteString())
delete(r.connections[peerID], c)
if len(r.connections[peerID]) == 0 {
......@@ -81,7 +81,7 @@ func (r *peerRegistry) add(c network.Conn, overlay swarm.Address) {
peerID := c.RemotePeer()
r.mu.Lock()
r.underlays[encodeunderlaysKey(overlay)] = peerID
r.underlays[overlay.ByteString()] = peerID
r.overlays[peerID] = overlay
if _, ok := r.connections[peerID]; !ok {
r.connections[peerID] = make(map[network.Conn]struct{})
......@@ -92,7 +92,7 @@ func (r *peerRegistry) add(c network.Conn, overlay swarm.Address) {
func (r *peerRegistry) peerID(overlay swarm.Address) (peerID libp2ppeer.ID, found bool) {
r.mu.RLock()
peerID, found = r.underlays[encodeunderlaysKey(overlay)]
peerID, found = r.underlays[overlay.ByteString()]
r.mu.RUnlock()
return peerID, found
}
......@@ -108,11 +108,7 @@ func (r *peerRegistry) remove(peerID libp2ppeer.ID) {
r.mu.Lock()
overlay := r.overlays[peerID]
delete(r.overlays, peerID)
delete(r.underlays, encodeunderlaysKey(overlay))
delete(r.underlays, overlay.ByteString())
delete(r.connections, peerID)
r.mu.Unlock()
}
func encodeunderlaysKey(overlay swarm.Address) string {
return string(overlay.Bytes())
}
......@@ -61,6 +61,11 @@ func (a Address) Bytes() []byte {
return a.b
}
// ByteString returns raw Address string without encoding.
func (a Address) ByteString() string {
return string(a.Bytes())
}
// UnmarshalJSON sets Address to a value from JSON-encoded representation.
func (a *Address) UnmarshalJSON(b []byte) (err error) {
var s string
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment