|
@ -11,11 +11,15 @@ import ( |
|
|
peer "github.com/ipfs/go-libp2p/p2p/peer" |
|
|
peer "github.com/ipfs/go-libp2p/p2p/peer" |
|
|
"gx/ipfs/QmQopLATEYMNg7dVqZRNDfeE2S1yKy8zrRh5xnYiuqeZBn/goprocess" |
|
|
"gx/ipfs/QmQopLATEYMNg7dVqZRNDfeE2S1yKy8zrRh5xnYiuqeZBn/goprocess" |
|
|
goprocessctx "gx/ipfs/QmQopLATEYMNg7dVqZRNDfeE2S1yKy8zrRh5xnYiuqeZBn/goprocess/context" |
|
|
goprocessctx "gx/ipfs/QmQopLATEYMNg7dVqZRNDfeE2S1yKy8zrRh5xnYiuqeZBn/goprocess/context" |
|
|
|
|
|
msmux "gx/ipfs/QmUeEcYJrzAEKdQXjzTxCgNZgc9sRuwharsvzzm5Gd2oGB/go-multistream" |
|
|
tec "gx/ipfs/QmWHgLqrghM9zw77nF6gdvT9ExQ2RB9pLxkd8sDHZf1rWb/go-temp-err-catcher" |
|
|
tec "gx/ipfs/QmWHgLqrghM9zw77nF6gdvT9ExQ2RB9pLxkd8sDHZf1rWb/go-temp-err-catcher" |
|
|
context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" |
|
|
context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" |
|
|
ma "gx/ipfs/QmcobAGsCjYt5DXoq9et9L8yR8er7o7Cu3DTvpaq12jYSz/go-multiaddr" |
|
|
ma "gx/ipfs/QmcobAGsCjYt5DXoq9et9L8yR8er7o7Cu3DTvpaq12jYSz/go-multiaddr" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
const SecioTag = "/secio/1.0.0" |
|
|
|
|
|
const NoEncryptionTag = "/plaintext/1.0.0" |
|
|
|
|
|
|
|
|
// ConnWrapper is any function that wraps a raw multiaddr connection
|
|
|
// ConnWrapper is any function that wraps a raw multiaddr connection
|
|
|
type ConnWrapper func(transport.Conn) transport.Conn |
|
|
type ConnWrapper func(transport.Conn) transport.Conn |
|
|
|
|
|
|
|
@ -31,6 +35,8 @@ type listener struct { |
|
|
wrapper ConnWrapper |
|
|
wrapper ConnWrapper |
|
|
|
|
|
|
|
|
proc goprocess.Process |
|
|
proc goprocess.Process |
|
|
|
|
|
|
|
|
|
|
|
mux *msmux.MultistreamMuxer |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (l *listener) teardown() error { |
|
|
func (l *listener) teardown() error { |
|
@ -98,6 +104,11 @@ func (l *listener) Accept() (net.Conn, error) { |
|
|
maconn = l.wrapper(maconn) |
|
|
maconn = l.wrapper(maconn) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
_, _, err = l.mux.Negotiate(maconn) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return nil, err |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
c, err := newSingleConn(ctx, l.local, "", maconn) |
|
|
c, err := newSingleConn(ctx, l.local, "", maconn) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
if catcher.IsTemporary(err) { |
|
|
if catcher.IsTemporary(err) { |
|
@ -150,9 +161,16 @@ func WrapTransportListener(ctx context.Context, ml transport.Listener, local pee |
|
|
Listener: ml, |
|
|
Listener: ml, |
|
|
local: local, |
|
|
local: local, |
|
|
privk: sk, |
|
|
privk: sk, |
|
|
|
|
|
mux: msmux.NewMultistreamMuxer(), |
|
|
} |
|
|
} |
|
|
l.proc = goprocessctx.WithContextAndTeardown(ctx, l.teardown) |
|
|
l.proc = goprocessctx.WithContextAndTeardown(ctx, l.teardown) |
|
|
|
|
|
|
|
|
|
|
|
if EncryptConnections { |
|
|
|
|
|
l.mux.AddHandler(SecioTag, nil) |
|
|
|
|
|
} else { |
|
|
|
|
|
l.mux.AddHandler(NoEncryptionTag, nil) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
log.Debugf("Conn Listener on %s", l.Multiaddr()) |
|
|
log.Debugf("Conn Listener on %s", l.Multiaddr()) |
|
|
log.Event(ctx, "swarmListen", l) |
|
|
log.Event(ctx, "swarmListen", l) |
|
|
return l, nil |
|
|
return l, nil |
|
|