Skip to content

Commit

Permalink
implement GetStreams
Browse files Browse the repository at this point in the history
  • Loading branch information
whyrusleeping committed Nov 3, 2016
1 parent 0ac5cdf commit 23bb096
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
8 changes: 7 additions & 1 deletion p2p/net/swarm/swarm_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,13 @@ func (c *Conn) Close() error {
}

func (c *Conn) GetStreams() ([]inet.Stream, error) {
return nil, fmt.Errorf("GetStreams() not yet implemented")
ss := c.StreamConn().Streams()
out := make([]inet.Stream, len(ss))

for i, s := range ss {
out[i] = (*Stream)(s)
}
return out, nil
}

func wrapConn(psc *ps.Conn) (*Conn, error) {
Expand Down
9 changes: 9 additions & 0 deletions p2p/net/swarm/swarm_net_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,15 @@ func TestNetworkOpenStream(t *testing.T) {
t.Fatal(err)
}

streams, err := nets[0].ConnsToPeer(nets[1].LocalPeer())[0].GetStreams()
if err != nil {
t.Fatal(err)
}

if len(streams) != 1 {
t.Fatal("should only have one stream there")
}

_, err = s.Write([]byte("hello ipfs"))
if err != nil {
t.Fatal(err)
Expand Down

0 comments on commit 23bb096

Please sign in to comment.