aboutsummaryrefslogtreecommitdiffstats
path: root/p2p/peer.go
diff options
context:
space:
mode:
authorJeffrey Wilcke <geffobscura@gmail.com>2015-06-30 08:22:19 +0800
committerJeffrey Wilcke <geffobscura@gmail.com>2015-06-30 08:22:19 +0800
commit7625b07dd9a2a7b5c5a504c1276eea04596ac871 (patch)
treece2a757cd4e0591fc15815b2dfae528ae517d36e /p2p/peer.go
parent72e2613a9fe3205fa5a67b72b832e03b2357ee88 (diff)
parent8f504063f465e0ca10c6bb53ee914d10a3d45c86 (diff)
downloadgo-tangerine-7625b07dd9a2a7b5c5a504c1276eea04596ac871.tar
go-tangerine-7625b07dd9a2a7b5c5a504c1276eea04596ac871.tar.gz
go-tangerine-7625b07dd9a2a7b5c5a504c1276eea04596ac871.tar.bz2
go-tangerine-7625b07dd9a2a7b5c5a504c1276eea04596ac871.tar.lz
go-tangerine-7625b07dd9a2a7b5c5a504c1276eea04596ac871.tar.xz
go-tangerine-7625b07dd9a2a7b5c5a504c1276eea04596ac871.tar.zst
go-tangerine-7625b07dd9a2a7b5c5a504c1276eea04596ac871.zip
Merge branch 'release/0.9.34'v0.9.34
Diffstat (limited to 'p2p/peer.go')
-rw-r--r--p2p/peer.go11
1 files changed, 9 insertions, 2 deletions
diff --git a/p2p/peer.go b/p2p/peer.go
index 40466cf84..e1bda1d03 100644
--- a/p2p/peer.go
+++ b/p2p/peer.go
@@ -249,15 +249,22 @@ func countMatchingProtocols(protocols []Protocol, caps []Cap) int {
// matchProtocols creates structures for matching named subprotocols.
func matchProtocols(protocols []Protocol, caps []Cap, rw MsgReadWriter) map[string]*protoRW {
- sort.Sort(capsByName(caps))
+ sort.Sort(capsByNameAndVersion(caps))
offset := baseProtocolLength
result := make(map[string]*protoRW)
+
outer:
for _, cap := range caps {
for _, proto := range protocols {
- if proto.Name == cap.Name && proto.Version == cap.Version && result[cap.Name] == nil {
+ if proto.Name == cap.Name && proto.Version == cap.Version {
+ // If an old protocol version matched, revert it
+ if old := result[cap.Name]; old != nil {
+ offset -= old.Length
+ }
+ // Assign the new match
result[cap.Name] = &protoRW{Protocol: proto, offset: offset, in: make(chan Msg), w: rw}
offset += proto.Length
+
continue outer
}
}