diff --git a/conn.go b/conn.go index fd3d5c3..7d986b6 100644 --- a/conn.go +++ b/conn.go @@ -3,7 +3,6 @@ package gostream import ( "context" "net" - "time" "github.com/libp2p/go-libp2p-core/host" "github.com/libp2p/go-libp2p-core/network" @@ -14,7 +13,7 @@ import ( // conn is an implementation of net.Conn which wraps // libp2p streams. type conn struct { - s network.Stream + network.Stream } // newConn creates a conn given a libp2p stream @@ -22,52 +21,14 @@ func newConn(s network.Stream) net.Conn { return &conn{s} } -// Read reads data from the connection. -func (c *conn) Read(b []byte) (n int, err error) { - return c.s.Read(b) -} - -// Write writes data to the connection. -func (c *conn) Write(b []byte) (n int, err error) { - return c.s.Write(b) -} - -// Close closes the connection. -// Any blocked Read or Write operations will be unblocked and return errors. -func (c *conn) Close() error { - return c.s.Close() -} - // LocalAddr returns the local network address. func (c *conn) LocalAddr() net.Addr { - return &addr{c.s.Conn().LocalPeer()} + return &addr{c.Stream.Conn().LocalPeer()} } // RemoteAddr returns the remote network address. func (c *conn) RemoteAddr() net.Addr { - return &addr{c.s.Conn().RemotePeer()} -} - -// SetDeadline sets the read and write deadlines associated -// with the connection. It is equivalent to calling both -// SetReadDeadline and SetWriteDeadline. -// See https://golang.org/pkg/net/#Conn for more details. -func (c *conn) SetDeadline(t time.Time) error { - return c.s.SetDeadline(t) -} - -// SetReadDeadline sets the deadline for future Read calls. -// A zero value for t means Read will not time out. -func (c *conn) SetReadDeadline(t time.Time) error { - return c.s.SetReadDeadline(t) -} - -// SetWriteDeadline sets the deadline for future Write calls. -// Even if write times out, it may return n > 0, indicating that -// some of the data was successfully written. -// A zero value for t means Write will not time out. -func (c *conn) SetWriteDeadline(t time.Time) error { - return c.s.SetWriteDeadline(t) + return &addr{c.Stream.Conn().RemotePeer()} } // Dial opens a stream to the destination address