Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
go-libp2p
Commits
33224773
Commit
33224773
authored
8 years ago
by
Jeromy Johnson
Committed by
GitHub
8 years ago
Browse files
Options
Download
Plain Diff
Merge pull request #170 from libp2p/feat/negotiate-lazy
update go-multistream and use negotiateLazy
parents
c0f09cbe
104c97ed
master
2018-Q4-OKR
docs-improvements
feat/p2p-multiaddr
feat/pnet/working3
feat/protobuf
feat/relay-integrate
feat/udp
feature/standardize-readme
fix/473
fix/no-custom-field
fix/reset-ping-stream
fix/revert-correct-external-addr
gx/update-jccl6u
gx/update-nza0mn
jenkinsfile
kevina/fix-go-vet
multistream-ping
punching
revert-276-update-go-detect-race
v6.0.23
v6.0.22
v6.0.21
v6.0.20
v6.0.19
v6.0.18
v6.0.17
v6.0.16
v6.0.15
v6.0.14
v6.0.13
v6.0.12
v6.0.11
v6.0.10
v6.0.9
v6.0.8
v6.0.7
v6.0.6
v6.0.5
v6.0.4
v6.0.3
v6.0.2
v6.0.1
v6.0.0
v5.0.21
v5.0.20
v5.0.19
v5.0.18
v5.0.17
v5.0.16
v5.0.15
v5.0.14
v5.0.13
v5.0.12
v5.0.11
v5.0.10
v5.0.9
v5.0.8
v5.0.7
v5.0.6
v5.0.5
v5.0.4
v5.0.3
v5.0.2
v5.0.1
v5.0.0
v4.5.5
v4.5.4
v4.5.3
v4.5.2
v4.5.1
v4.5.0
v4.4.5
v4.4.4
v4.4.3
v4.4.2
v4.4.1
v4.4.0
v4.3.12
v4.3.11
v4.3.10
v4.3.9
v4.3.8
v4.3.7
v4.3.6
v4.3.5
v4.3.4
v4.3.3
v4.3.2
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
p2p/host/basic/basic_host.go
+13
-1
p2p/host/basic/basic_host.go
p2p/host/basic/basic_host_test.go
+15
-5
p2p/host/basic/basic_host_test.go
p2p/protocol/identify/id.go
+3
-3
p2p/protocol/identify/id.go
package.json
+12
-12
package.json
with
43 additions
and
21 deletions
+43
-21
p2p/host/basic/basic_host.go
View file @
33224773
...
...
@@ -104,6 +104,9 @@ func New(net inet.Network, opts ...interface{}) *BasicHost {
// newConnHandler is the remote-opened conn handler for inet.Network
func
(
h
*
BasicHost
)
newConnHandler
(
c
inet
.
Conn
)
{
// Clear protocols on connecting to new peer to avoid issues caused
// by misremembering protocols between reconnects
h
.
Peerstore
()
.
SetProtocols
(
c
.
RemotePeer
())
h
.
ids
.
IdentifyConn
(
c
)
}
...
...
@@ -120,7 +123,7 @@ func (h *BasicHost) newStreamHandler(s inet.Stream) {
}
}
protoID
,
handle
,
err
:=
h
.
Mux
()
.
Negotiate
(
s
)
lzc
,
protoID
,
handle
,
err
:=
h
.
Mux
()
.
Negotiate
Lazy
(
s
)
took
:=
time
.
Now
()
.
Sub
(
before
)
if
err
!=
nil
{
if
err
==
io
.
EOF
{
...
...
@@ -136,6 +139,11 @@ func (h *BasicHost) newStreamHandler(s inet.Stream) {
return
}
s
=
&
streamWrapper
{
Stream
:
s
,
rw
:
lzc
,
}
if
h
.
NegotiateTimeout
!=
0
{
if
err
:=
s
.
SetDeadline
(
time
.
Time
{});
err
!=
nil
{
log
.
Error
(
"resetting stream deadline: "
,
err
)
...
...
@@ -316,6 +324,10 @@ func (h *BasicHost) dialPeer(ctx context.Context, p peer.ID) error {
return
err
}
// Clear protocols on connecting to new peer to avoid issues caused
// by misremembering protocols between reconnects
h
.
Peerstore
()
.
SetProtocols
(
p
)
// identify the connection before returning.
done
:=
make
(
chan
struct
{})
go
func
()
{
...
...
This diff is collapsed.
Click to expand it.
p2p/host/basic/basic_host_test.go
View file @
33224773
...
...
@@ -98,7 +98,7 @@ func TestHostProtoPreference(t *testing.T) {
protoNew
:=
protocol
.
ID
(
"/testing/1.1.0"
)
protoMinor
:=
protocol
.
ID
(
"/testing/1.2.0"
)
connectedOn
:=
make
(
chan
protocol
.
ID
,
16
)
connectedOn
:=
make
(
chan
protocol
.
ID
)
handler
:=
func
(
s
inet
.
Stream
)
{
connectedOn
<-
s
.
Protocol
()
...
...
@@ -173,7 +173,7 @@ func TestHostProtoPreknowledge(t *testing.T) {
h1
:=
New
(
testutil
.
GenSwarmNetwork
(
t
,
ctx
))
h2
:=
New
(
testutil
.
GenSwarmNetwork
(
t
,
ctx
))
conn
:=
make
(
chan
protocol
.
ID
,
16
)
conn
:=
make
(
chan
protocol
.
ID
)
handler
:=
func
(
s
inet
.
Stream
)
{
conn
<-
s
.
Protocol
()
s
.
Close
()
...
...
@@ -189,7 +189,17 @@ func TestHostProtoPreknowledge(t *testing.T) {
defer
h2
.
Close
()
// wait for identify handshake to finish completely
time
.
Sleep
(
time
.
Millisecond
*
20
)
select
{
case
<-
h1
.
ids
.
IdentifyWait
(
h1
.
Network
()
.
ConnsToPeer
(
h2
.
ID
())[
0
])
:
case
<-
time
.
After
(
time
.
Second
*
5
)
:
t
.
Fatal
(
"timed out waiting for identify"
)
}
select
{
case
<-
h2
.
ids
.
IdentifyWait
(
h2
.
Network
()
.
ConnsToPeer
(
h1
.
ID
())[
0
])
:
case
<-
time
.
After
(
time
.
Second
*
5
)
:
t
.
Fatal
(
"timed out waiting for identify"
)
}
h1
.
SetStreamHandler
(
"/foo"
,
handler
)
...
...
@@ -222,7 +232,7 @@ func TestNewDialOld(t *testing.T) {
defer
h1
.
Close
()
defer
h2
.
Close
()
connectedOn
:=
make
(
chan
protocol
.
ID
,
16
)
connectedOn
:=
make
(
chan
protocol
.
ID
)
h1
.
SetStreamHandler
(
"/testing"
,
func
(
s
inet
.
Stream
)
{
connectedOn
<-
s
.
Protocol
()
s
.
Close
()
...
...
@@ -250,7 +260,7 @@ func TestProtoDowngrade(t *testing.T) {
defer
h1
.
Close
()
defer
h2
.
Close
()
connectedOn
:=
make
(
chan
protocol
.
ID
,
16
)
connectedOn
:=
make
(
chan
protocol
.
ID
)
h1
.
SetStreamHandler
(
"/testing/1.0.0"
,
func
(
s
inet
.
Stream
)
{
connectedOn
<-
s
.
Protocol
()
s
.
Close
()
...
...
This diff is collapsed.
Click to expand it.
p2p/protocol/identify/id.go
View file @
33224773
...
...
@@ -100,8 +100,7 @@ func (ids *IDService) IdentifyConn(c inet.Conn) {
// ok give the response to our handler.
if
err
:=
msmux
.
SelectProtoOrFail
(
ID
,
s
);
err
!=
nil
{
log
.
Debugf
(
"error writing stream header for %s"
,
ID
)
log
.
Event
(
context
.
TODO
(),
"IdentifyOpenFailed"
,
c
.
RemotePeer
())
log
.
Event
(
context
.
TODO
(),
"IdentifyOpenFailed"
,
c
.
RemotePeer
(),
logging
.
Metadata
{
"error"
:
err
})
return
}
...
...
@@ -113,7 +112,7 @@ func (ids *IDService) IdentifyConn(c inet.Conn) {
ids
.
currmu
.
Unlock
()
if
!
found
{
log
.
Debug
f
(
"IdentifyConn failed to find channel (programmer error) for %s"
,
c
)
log
.
Error
f
(
"IdentifyConn failed to find channel (programmer error) for %s"
,
c
)
return
}
}
...
...
@@ -142,6 +141,7 @@ func (ids *IDService) ResponseHandler(s inet.Stream) {
r
:=
ggio
.
NewDelimitedReader
(
s
,
2048
)
mes
:=
pb
.
Identify
{}
if
err
:=
r
.
ReadMsg
(
&
mes
);
err
!=
nil
{
log
.
Warning
(
"error reading identify message: "
,
err
)
return
}
ids
.
consumeMessage
(
&
mes
,
c
)
...
...
This diff is collapsed.
Click to expand it.
package.json
View file @
33224773
...
...
@@ -34,9 +34,9 @@
"version"
:
"1.0.0"
},
{
"hash"
:
"Qm
atJnBK2qyjcy1AYq4Gb5YH16YM7uibdteQ589r46YLvB
"
,
"hash"
:
"Qm
cpkzwqeqEnMgrmR4E48Ex52fcQU7eJz11gXk3qEit95q
"
,
"name"
:
"go-multistream"
,
"version"
:
"0.3.
1
"
"version"
:
"0.3.
5
"
},
{
"hash"
:
"QmQHGMVmrsgmqUG8ih3puNXUJneSpi13dkcZpzLKkskUkH"
,
...
...
@@ -187,9 +187,9 @@
},
{
"author"
:
"whyrusleeping"
,
"hash"
:
"Qm
QKfJb2rWd7vCzf38VEx9NQWUkuqfd5KuGo6eZEtQLNcQ
"
,
"hash"
:
"Qm
dEajEhjdowKAsrZiaZBWnZkdREjT32UZAsfhAfcmonr3
"
,
"name"
:
"go-libp2p-conn"
,
"version"
:
"1.5.
1
"
"version"
:
"1.5.
4
"
},
{
"author"
:
"whyrusleeping"
,
...
...
@@ -211,15 +211,15 @@
},
{
"author"
:
"whyrusleeping"
,
"hash"
:
"Qm
PTGbC34bPKaUm9wTxBo7zSCac7pDuG42ZmnXC718CKZZ
"
,
"hash"
:
"Qm
b55YjV8z4PNChVKZM5rehSFLtgDURmDZ8d3DdkvBBZR1
"
,
"name"
:
"go-libp2p-host"
,
"version"
:
"1.3.
1
"
"version"
:
"1.3.
4
"
},
{
"author"
:
"whyrusleeping"
,
"hash"
:
"Qm
WfxnAiQ5TnnCgiX9ikVUKFNHRgGhbgKdx5DoKPELD7P4
"
,
"hash"
:
"Qm
fSEkiXoCxTkRajpiHiyruDGSGpX9n6NivdFQJWBGVCQM
"
,
"name"
:
"go-libp2p-swarm"
,
"version"
:
"1.6.
1
"
"version"
:
"1.6.
4
"
},
{
"author"
:
"whyrusleeping"
,
...
...
@@ -229,15 +229,15 @@
},
{
"author"
:
"whyrusleeping"
,
"hash"
:
"Qm
WdGJY4fcsfhLHucEfivw8J71yUqNUFbzdU1jnJBnN5Xh
"
,
"hash"
:
"Qm
UcaGGriHNMtx7udfjUFQ7yDVq8zopYRDey5Lj68z5DZQ
"
,
"name"
:
"go-libp2p-netutil"
,
"version"
:
"0.2.
1
"
"version"
:
"0.2.
4
"
},
{
"author"
:
"whyrusleeping"
,
"hash"
:
"Qm
SzhYTPRvh5nUJnRfYBW52QGX6jekULCRQcrxRs8hmzj4
"
,
"hash"
:
"Qm
Rg8JoySAwWunyjZwwo8fbm5ysw3vv3ggSHcmw8KXzk6f
"
,
"name"
:
"go-libp2p-blankhost"
,
"version"
:
"0.1.
1
"
"version"
:
"0.1.
4
"
}
],
"gxVersion"
:
"0.4.0"
,
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help