github.com/NebulousLabs/Sia@v1.3.7/modules/gateway/conn.go (about)

     1  package gateway
     2  
     3  import (
     4  	"net"
     5  	"time"
     6  
     7  	"github.com/NebulousLabs/Sia/modules"
     8  )
     9  
    10  // peerConn is a simple type that implements the modules.PeerConn interface.
    11  type peerConn struct {
    12  	net.Conn
    13  	dialbackAddr modules.NetAddress
    14  }
    15  
    16  // RPCAddr implements the RPCAddr method of the modules.PeerConn interface. It
    17  // is the address that identifies a peer.
    18  func (pc peerConn) RPCAddr() modules.NetAddress {
    19  	return pc.dialbackAddr
    20  }
    21  
    22  // staticDial will staticDial the input address and return a connection. staticDial appropriately
    23  // handles things like clean shutdown, fast shutdown, and chooses the correct
    24  // communication protocol.
    25  func (g *Gateway) staticDial(addr modules.NetAddress) (net.Conn, error) {
    26  	dialer := &net.Dialer{
    27  		Cancel:  g.threads.StopChan(),
    28  		Timeout: dialTimeout,
    29  	}
    30  	conn, err := dialer.Dial("tcp", string(addr))
    31  	if err != nil {
    32  		return nil, err
    33  	}
    34  	conn.SetDeadline(time.Now().Add(connStdDeadline))
    35  	return conn, nil
    36  }