Commit 73f16a9f authored by Jeromy Johnson's avatar Jeromy Johnson Committed by GitHub
Browse files

Merge pull request #159 from libp2p/feat/set-protos

address protocol downgrade bug
parents 4855e003 f4ea270c
...@@ -241,3 +241,62 @@ func TestNewDialOld(t *testing.T) { ...@@ -241,3 +241,62 @@ func TestNewDialOld(t *testing.T) {
s.Close() s.Close()
} }
func TestProtoDowngrade(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
h1, h2 := getHostPair(ctx, t)
defer h1.Close()
defer h2.Close()
connectedOn := make(chan protocol.ID, 16)
h1.SetStreamHandler("/testing/1.0.0", func(s inet.Stream) {
connectedOn <- s.Protocol()
s.Close()
})
s, err := h2.NewStream(ctx, h1.ID(), "/testing/1.0.0", "/testing")
if err != nil {
t.Fatal(err)
}
assertWait(t, connectedOn, "/testing/1.0.0")
if s.Protocol() != "/testing/1.0.0" {
t.Fatal("shoould have gotten /testing")
}
s.Close()
h1.Network().ConnsToPeer(h2.ID())[0].Close()
time.Sleep(time.Millisecond * 50) // allow notifications to propogate
h1.RemoveStreamHandler("/testing/1.0.0")
h1.SetStreamHandler("/testing", func(s inet.Stream) {
connectedOn <- s.Protocol()
s.Close()
})
h2pi := h2.Peerstore().PeerInfo(h2.ID())
if err := h1.Connect(ctx, h2pi); err != nil {
t.Fatal(err)
}
s2, err := h2.NewStream(ctx, h1.ID(), "/testing/1.0.0", "/testing")
if err != nil {
t.Fatal(err)
}
_, err = s2.Write(nil)
if err != nil {
t.Fatal(err)
}
assertWait(t, connectedOn, "/testing")
if s2.Protocol() != "/testing" {
t.Fatal("shoould have gotten /testing")
}
s2.Close()
}
...@@ -193,7 +193,7 @@ func (ids *IDService) consumeMessage(mes *pb.Identify, c inet.Conn) { ...@@ -193,7 +193,7 @@ func (ids *IDService) consumeMessage(mes *pb.Identify, c inet.Conn) {
p := c.RemotePeer() p := c.RemotePeer()
// mes.Protocols // mes.Protocols
ids.Host.Peerstore().AddProtocols(p, mes.Protocols...) ids.Host.Peerstore().SetProtocols(p, mes.Protocols...)
// mes.ObservedAddr // mes.ObservedAddr
ids.consumeObservedAddress(mes.GetObservedAddr(), c) ids.consumeObservedAddress(mes.GetObservedAddr(), c)
......
...@@ -139,9 +139,9 @@ ...@@ -139,9 +139,9 @@
}, },
{ {
"author": "whyrusleeping", "author": "whyrusleeping",
"hash": "QmXXCcQ7CLg5a81Ui9TTR35QcR4y7ZyihxwfjqaHfUVcVo", "hash": "QmeXj9VAjmYQZxpmVz7VzccbJrpmr8qkCDSjfVNsPTWTYU",
"name": "go-libp2p-peerstore", "name": "go-libp2p-peerstore",
"version": "1.3.0" "version": "1.4.0"
}, },
{ {
"author": "whyrusleeping", "author": "whyrusleeping",
...@@ -193,15 +193,15 @@ ...@@ -193,15 +193,15 @@
}, },
{ {
"author": "whyrusleeping", "author": "whyrusleeping",
"hash": "QmU3pGGVT1riXp5dBJbNrGpxssVScfvk9236drRHZZbKJ1", "hash": "QmQx1dHDDYENugYgqA22BaBrRfuv1coSsuPiM7rYh1wwGH",
"name": "go-libp2p-net", "name": "go-libp2p-net",
"version": "1.6.0" "version": "1.6.1"
}, },
{ {
"author": "whyrusleeping", "author": "whyrusleeping",
"hash": "QmX4j1JhubdEt4EB1JY1mMKTvJwPZSRzTv3uwh5zaDqyAi", "hash": "QmY2otvyPM2sTaDsczo7Yuosg98sUMCJ9qx1gpPaAPTS9B",
"name": "go-libp2p-metrics", "name": "go-libp2p-metrics",
"version": "1.6.0" "version": "1.6.1"
}, },
{ {
"author": "whyrusleeping", "author": "whyrusleeping",
...@@ -211,15 +211,15 @@ ...@@ -211,15 +211,15 @@
}, },
{ {
"author": "whyrusleeping", "author": "whyrusleeping",
"hash": "Qmb6UFbVu1grhv5o5KnouvtZ6cqdrjXj6zLejAHWunxgCt", "hash": "QmPTGbC34bPKaUm9wTxBo7zSCac7pDuG42ZmnXC718CKZZ",
"name": "go-libp2p-host", "name": "go-libp2p-host",
"version": "1.3.0" "version": "1.3.1"
}, },
{ {
"author": "whyrusleeping", "author": "whyrusleeping",
"hash": "QmNafAGBU21iQmLudMT2z1kqgEGhjUrNoK9a3v4azd8ei4", "hash": "QmV82zccDVU2fPv7E6wBD6cPy55brSFGHNeTVg5MZ6ZDQ8",
"name": "go-libp2p-swarm", "name": "go-libp2p-swarm",
"version": "1.5.0" "version": "1.5.1"
}, },
{ {
"author": "whyrusleeping", "author": "whyrusleeping",
...@@ -229,15 +229,15 @@ ...@@ -229,15 +229,15 @@
}, },
{ {
"author": "whyrusleeping", "author": "whyrusleeping",
"hash": "QmcDTquYLTYirqj71RRWKUWEEw3nJt11Awzun5ep8kfY7W", "hash": "QmbUDXBMqSe4VCRgTMeAfyBh1T3GBnELEBXobZDL7cjVgs",
"name": "go-libp2p-netutil", "name": "go-libp2p-netutil",
"version": "0.1.0" "version": "0.1.1"
}, },
{ {
"author": "whyrusleeping", "author": "whyrusleeping",
"hash": "QmYjDhB1VkuP5ATkqjdnPHfA2huyfcydNMXoGdtEvTNcYL", "hash": "QmSzhYTPRvh5nUJnRfYBW52QGX6jekULCRQcrxRs8hmzj4",
"name": "go-libp2p-blankhost", "name": "go-libp2p-blankhost",
"version": "0.1.0" "version": "0.1.1"
} }
], ],
"gxVersion": "0.4.0", "gxVersion": "0.4.0",
......
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