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
c0e2b930
Commit
c0e2b930
authored
8 years ago
by
Jeromy
Browse files
Options
Download
Email Patches
Plain Diff
update multistream deps and fix code to work with new changes
parent
5b9cd671
master
2018-Q4-OKR
docs-improvements
feat/backoff-listing
feat/p2p-multiaddr
feat/pnet/working3
feat/protobuf
feat/relay-integrate
feat/udp
feat/update/go-reuseport
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
v4.3.1
v4.3.0
v4.2.0
v4.1.0
v4.0.4
v4.0.3
v4.0.2
v4.0.1
v4.0.0
v3.6.0
v3.5.4
v3.5.3
v3.5.2
v3.5.1
v3.5.0
v3.4.3
v3.4.2
v3.4.1
v3.4.0
No related merge requests found
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
examples/hosts/main.go
+0
-1
examples/hosts/main.go
p2p/host/basic/basic_host.go
+6
-3
p2p/host/basic/basic_host.go
p2p/net/conn/dial_test.go
+1
-1
p2p/net/conn/dial_test.go
p2p/net/interface.go
+3
-0
p2p/net/interface.go
p2p/net/mock/mock_stream.go
+10
-0
p2p/net/mock/mock_stream.go
p2p/net/swarm/swarm.go
+2
-2
p2p/net/swarm/swarm.go
p2p/net/swarm/swarm_notif_test.go
+8
-2
p2p/net/swarm/swarm_notif_test.go
p2p/net/swarm/swarm_stream.go
+20
-7
p2p/net/swarm/swarm_stream.go
package.json
+4
-4
package.json
with
54 additions
and
20 deletions
+54
-20
examples/hosts/main.go
View file @
c0e2b930
...
...
@@ -5,7 +5,6 @@ import (
"fmt"
"io/ioutil"
"log"
"time"
pstore
"github.com/ipfs/go-libp2p-peerstore"
host
"github.com/ipfs/go-libp2p/p2p/host"
...
...
This diff is collapsed.
Click to expand it.
p2p/host/basic/basic_host.go
View file @
c0e2b930
...
...
@@ -114,7 +114,8 @@ func (h *BasicHost) newStreamHandler(s inet.Stream) {
logStream
:=
mstream
.
WrapStream
(
s
,
protocol
.
ID
(
protoID
),
h
.
bwc
)
go
handle
(
logStream
)
s
.
SetProtocol
(
protoID
)
go
handle
(
protoID
,
logStream
)
}
// ID returns the (local) peer.ID associated with this Host
...
...
@@ -147,8 +148,10 @@ func (h *BasicHost) IDService() *identify.IDService {
// host.Mux().SetHandler(proto, handler)
// (Threadsafe)
func
(
h
*
BasicHost
)
SetStreamHandler
(
pid
protocol
.
ID
,
handler
inet
.
StreamHandler
)
{
h
.
Mux
()
.
AddHandler
(
string
(
pid
),
func
(
rwc
io
.
ReadWriteCloser
)
error
{
handler
(
rwc
.
(
inet
.
Stream
))
h
.
Mux
()
.
AddHandler
(
string
(
pid
),
func
(
p
string
,
rwc
io
.
ReadWriteCloser
)
error
{
is
:=
rwc
.
(
inet
.
Stream
)
is
.
SetProtocol
(
p
)
handler
(
is
)
return
nil
})
}
...
...
This diff is collapsed.
Click to expand it.
p2p/net/conn/dial_test.go
View file @
c0e2b930
...
...
@@ -23,7 +23,7 @@ import (
)
func
goroFilter
(
r
*
grc
.
Goroutine
)
bool
{
return
strings
.
Contains
(
r
.
Function
,
"go-log."
)
return
strings
.
Contains
(
r
.
Function
,
"go-log."
)
||
strings
.
Contains
(
r
.
Stack
[
0
],
"testing.(*T).Run"
)
}
func
echoListen
(
ctx
context
.
Context
,
listener
Listener
)
{
...
...
This diff is collapsed.
Click to expand it.
p2p/net/interface.go
View file @
c0e2b930
...
...
@@ -26,6 +26,9 @@ type Stream interface {
io
.
Writer
io
.
Closer
Protocol
()
string
SetProtocol
(
string
)
// Conn returns the connection this stream is part of.
Conn
()
Conn
}
...
...
This diff is collapsed.
Click to expand it.
p2p/net/mock/mock_stream.go
View file @
c0e2b930
...
...
@@ -16,6 +16,8 @@ type stream struct {
conn
*
conn
toDeliver
chan
*
transportObject
proc
process
.
Process
protocol
string
}
type
transportObject
struct
{
...
...
@@ -48,6 +50,14 @@ func (s *stream) Write(p []byte) (n int, err error) {
return
len
(
p
),
nil
}
func
(
s
*
stream
)
Protocol
()
string
{
return
s
.
protocol
}
func
(
s
*
stream
)
SetProtocol
(
proto
string
)
{
s
.
protocol
=
proto
}
func
(
s
*
stream
)
Close
()
error
{
return
s
.
proc
.
Close
()
}
...
...
This diff is collapsed.
Click to expand it.
p2p/net/swarm/swarm.go
View file @
c0e2b930
...
...
@@ -340,9 +340,9 @@ func (n *ps2netNotifee) Disconnected(c *ps.Conn) {
}
func
(
n
*
ps2netNotifee
)
OpenedStream
(
s
*
ps
.
Stream
)
{
n
.
not
.
OpenedStream
(
n
.
net
,
inet
.
Stream
((
*
S
tream
)(
s
))
)
n
.
not
.
OpenedStream
(
n
.
net
,
&
Stream
{
s
tream
:
s
}
)
}
func
(
n
*
ps2netNotifee
)
ClosedStream
(
s
*
ps
.
Stream
)
{
n
.
not
.
ClosedStream
(
n
.
net
,
inet
.
Stream
((
*
S
tream
)(
s
))
)
n
.
not
.
ClosedStream
(
n
.
net
,
&
Stream
{
s
tream
:
s
}
)
}
This diff is collapsed.
Click to expand it.
p2p/net/swarm/swarm_notif_test.go
View file @
c0e2b930
...
...
@@ -10,6 +10,12 @@ import (
context
"golang.org/x/net/context"
)
func
streamsSame
(
a
,
b
inet
.
Stream
)
bool
{
sa
:=
a
.
(
*
Stream
)
sb
:=
b
.
(
*
Stream
)
return
sa
.
Stream
()
==
sb
.
Stream
()
}
func
TestNotifications
(
t
*
testing
.
T
)
{
ctx
:=
context
.
Background
()
swarms
:=
makeSwarms
(
ctx
,
t
,
5
)
...
...
@@ -98,7 +104,7 @@ func TestNotifications(t *testing.T) {
case
<-
time
.
After
(
timeout
)
:
t
.
Fatal
(
"timeout"
)
}
if
s
!=
s2
{
if
!
streamsSame
(
s
,
s2
)
{
t
.
Fatal
(
"got incorrect stream"
,
s
.
Conn
(),
s2
.
Conn
())
}
...
...
@@ -108,7 +114,7 @@ func TestNotifications(t *testing.T) {
case
<-
time
.
After
(
timeout
)
:
t
.
Fatal
(
"timeout"
)
}
if
s
!=
s2
{
if
!
streamsSame
(
s
,
s2
)
{
t
.
Fatal
(
"got incorrect stream"
,
s
.
Conn
(),
s2
.
Conn
())
}
}
...
...
This diff is collapsed.
Click to expand it.
p2p/net/swarm/swarm_stream.go
View file @
c0e2b930
...
...
@@ -8,11 +8,14 @@ import (
// a Stream is a wrapper around a ps.Stream that exposes a way to get
// our Conn and Swarm (instead of just the ps.Conn and ps.Swarm)
type
Stream
ps
.
Stream
type
Stream
struct
{
stream
*
ps
.
Stream
protocol
string
}
// Stream returns the underlying peerstream.Stream
func
(
s
*
Stream
)
Stream
()
*
ps
.
Stream
{
return
(
*
p
s
.
S
tream
)(
s
)
return
s
.
s
tream
}
// Conn returns the Conn associated with this Stream, as an inet.Conn
...
...
@@ -22,27 +25,37 @@ func (s *Stream) Conn() inet.Conn {
// SwarmConn returns the Conn associated with this Stream, as a *Conn
func
(
s
*
Stream
)
SwarmConn
()
*
Conn
{
return
(
*
Conn
)(
s
.
S
tream
()
.
Conn
())
return
(
*
Conn
)(
s
.
s
tream
.
Conn
())
}
// Read reads bytes from a stream.
func
(
s
*
Stream
)
Read
(
p
[]
byte
)
(
n
int
,
err
error
)
{
return
s
.
S
tream
()
.
Read
(
p
)
return
s
.
s
tream
.
Read
(
p
)
}
// Write writes bytes to a stream, flushing for each call.
func
(
s
*
Stream
)
Write
(
p
[]
byte
)
(
n
int
,
err
error
)
{
return
s
.
S
tream
()
.
Write
(
p
)
return
s
.
s
tream
.
Write
(
p
)
}
// Close closes the stream, indicating this side is finished
// with the stream.
func
(
s
*
Stream
)
Close
()
error
{
return
s
.
Stream
()
.
Close
()
return
s
.
stream
.
Close
()
}
func
(
s
*
Stream
)
Protocol
()
string
{
return
s
.
protocol
}
func
(
s
*
Stream
)
SetProtocol
(
p
string
)
{
s
.
protocol
=
p
}
func
wrapStream
(
pss
*
ps
.
Stream
)
*
Stream
{
return
(
*
Stream
)(
pss
)
return
&
Stream
{
stream
:
pss
,
}
}
func
wrapStreams
(
st
[]
*
ps
.
Stream
)
[]
*
Stream
{
...
...
This diff is collapsed.
Click to expand it.
package.json
View file @
c0e2b930
...
...
@@ -34,9 +34,9 @@
"version"
:
"1.0.0"
},
{
"hash"
:
"Qm
f91yhgRLo2dhhbc5zZ7TxjMaR1oxaWaoc9zRZdi1kU4a
"
,
"hash"
:
"Qm
c8WfU6Ci9e1qvTNYE3EUwrHEXfpxY7dNrWtVtjpYcp2P
"
,
"name"
:
"go-multistream"
,
"version"
:
"0.
0
.0"
"version"
:
"0.
1
.0"
},
{
"hash"
:
"QmNLvkCDV6ZjUJsEwGNporYBuZdhWT6q7TBVYQwwRv12HT"
,
...
...
@@ -171,9 +171,9 @@
},
{
"author"
:
"whyrusleeping"
,
"hash"
:
"Qm
VcmcQE9eX4HQ8QwhVXpoHt3ennG7d299NDYFq9D1Uqa1
"
,
"hash"
:
"Qm
RbnoT3xJXpi37Vc11e6VYV4RXKWUMsZtfbBQkR43377P
"
,
"name"
:
"go-smux-multistream"
,
"version"
:
"1.
0
.0"
"version"
:
"1.
1
.0"
},
{
"author"
:
"whyrusleeping"
,
...
...
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