Commit b3807808 authored by Steven Allen's avatar Steven Allen Committed by GitHub

Merge pull request #8 from marten-seemann/master

Compatibility with the new transport interfaces
parents 9e9c6d16 36c4213d
1.2.2: QmdQcv14hCd41WEzNA4avJohJR5sdPqVgFtXZtDz6MTCKx
2.0.0: QmbZD4YSQDKW99RYos6zwNxDJnNe2Bem72fH4nNVZMDdS8
......@@ -27,9 +27,9 @@
},
{
"author": "whyrusleeping",
"hash": "QmQVm7pWYKPStMeMrXNRpvAJE5rSm9ThtQoNmjNHC7sh3k",
"hash": "QmYcK2kPkJmj9GMxKvLhD4REtAkeuaN8sqDEJePmEqHQnp",
"name": "go-libp2p-transport",
"version": "2.2.8"
"version": "3.0.0"
},
{
"hash": "QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52",
......@@ -48,6 +48,6 @@
"license": "MIT",
"name": "go-tcp-transport",
"releaseCmd": "git commit -a -m \"gx publish $VERSION\"",
"version": "1.2.2"
"version": "2.0.0"
}
......@@ -5,7 +5,6 @@ import (
"fmt"
"net"
"sync"
"time"
logging "github.com/ipfs/go-log"
reuseport "github.com/jbenet/go-reuseport"
......@@ -25,6 +24,8 @@ type TcpTransport struct {
listeners map[string]tpt.Listener
}
var _ tpt.Transport = &TcpTransport{}
// NewTCPTransport creates a tcp transport object that tracks dialers and listeners
// created. It represents an entire tcp stack (though it might not necessarily be)
func NewTCPTransport() *TcpTransport {
......@@ -54,8 +55,6 @@ func (t *TcpTransport) Dialer(laddr ma.Multiaddr, opts ...tpt.DialOpt) (tpt.Dial
var doReuse bool
for _, o := range opts {
switch o := o.(type) {
case tpt.TimeoutOpt:
base.Timeout = time.Duration(o)
case tpt.ReuseportOpt:
doReuse = bool(o)
default:
......@@ -135,6 +134,8 @@ type tcpDialer struct {
transport tpt.Transport
}
var _ tpt.Dialer = &tcpDialer{}
func (t *TcpTransport) newTcpDialer(base manet.Dialer, laddr ma.Multiaddr, doReuse bool) (*tcpDialer, error) {
// get the local net.Addr manually
la, err := manet.ToNetAddr(laddr)
......@@ -195,9 +196,9 @@ func (d *tcpDialer) DialContext(ctx context.Context, raddr ma.Multiaddr) (tpt.Co
return nil, err
}
return &tpt.ConnWrap{
return &tcpConn{
Conn: c,
Tpt: d.transport,
t: d.transport,
}, nil
}
......@@ -238,15 +239,17 @@ type tcpListener struct {
transport tpt.Transport
}
var _ tpt.Listener = &tcpListener{}
func (d *tcpListener) Accept() (tpt.Conn, error) {
c, err := d.list.Accept()
if err != nil {
return nil, err
}
return &tpt.ConnWrap{
return &tcpConn{
Conn: c,
Tpt: d.transport,
t: d.transport,
}, nil
}
......@@ -265,3 +268,15 @@ func (t *tcpListener) NetListener() net.Listener {
func (d *tcpListener) Close() error {
return d.list.Close()
}
type tcpConn struct {
manet.Conn
t tpt.Transport
}
var _ tpt.Conn = &tcpConn{}
var _ tpt.DuplexConn = &tcpConn{}
func (c *tcpConn) Transport() tpt.Transport {
return c.t
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment