提交 78c0802f 作者: Juan Batiz-Benet

connect swarm context to network

上级 ba323c3e
......@@ -4,7 +4,6 @@ package net
import (
swarm "github.com/jbenet/go-ipfs/net/swarm2"
peer "github.com/jbenet/go-ipfs/peer"
util "github.com/jbenet/go-ipfs/util"
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
ctxgroup "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-ctxgroup"
......@@ -117,10 +116,7 @@ func NewNetwork(ctx context.Context, listen []ma.Multiaddr, local peer.Peer,
// DialPeer attempts to establish a connection to a given peer.
// Respects the context.
func (n *network) DialPeer(ctx context.Context, p peer.Peer) error {
err := util.ContextDo(ctx, func() error {
_, err := n.swarm.Dial(p)
return err
})
_, err := n.swarm.Dial(ctx, p)
return err
}
......
......@@ -30,7 +30,7 @@ func TestSimultOpen(t *testing.T) {
cp := testutil.NewPeerWithID(dst.ID())
cp.AddAddress(dst.Addresses()[0])
if _, err := s.Dial(cp); err != nil {
if _, err := s.Dial(ctx, cp); err != nil {
t.Fatal("error swarm dialing to peer", err)
}
wg.Done()
......
......@@ -90,7 +90,7 @@ func (s *Swarm) NewStreamWithPeer(p peer.Peer) (*Stream, error) {
// if we have no connections, try connecting.
if len(s.ConnectionsToPeer(p)) == 0 {
log.Debug("Swarm: NewStreamWithPeer no connections. Attempting to connect...")
if _, err := s.Dial(p); err != nil {
if _, err := s.Dial(context.Background(), p); err != nil {
return nil, err
}
}
......
......@@ -17,8 +17,7 @@ import (
// the connection will happen over. Swarm can use whichever it choses.
// This allows us to use various transport protocols, do NAT traversal/relay,
// etc. to achive connection.
func (s *Swarm) Dial(p peer.Peer) (*Conn, error) {
ctx := context.TODO()
func (s *Swarm) Dial(ctx context.Context, p peer.Peer) (*Conn, error) {
if p.ID().Equal(s.local.ID()) {
return nil, errors.New("Attempted connection to self!")
......
......@@ -108,7 +108,7 @@ func SubtestSwarm(t *testing.T, addrs []string, MsgNum int) {
cp.AddAddress(dst.Addresses()[0])
log.Infof("SWARM TEST: %s dialing %s", s.local, dst)
if _, err := s.Dial(cp); err != nil {
if _, err := s.Dial(ctx, cp); err != nil {
t.Fatal("error swarm dialing to peer", err)
}
log.Infof("SWARM TEST: %s connected to %s", s.local, dst)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论