diff --git a/vendor/github.com/SkycoinProject/dmsg/client.go b/vendor/github.com/SkycoinProject/dmsg/client.go index 178db86041..3a3b037b26 100644 --- a/vendor/github.com/SkycoinProject/dmsg/client.go +++ b/vendor/github.com/SkycoinProject/dmsg/client.go @@ -35,7 +35,8 @@ type Client struct { done chan struct{} once sync.Once - sesMx sync.Mutex + sesMx sync.Mutex + dialMx sync.Mutex // stream dial mutex. } // NewClient creates a dmsg client entity. @@ -171,6 +172,14 @@ func (ce *Client) Dial(ctx context.Context, addr Addr) (net.Conn, error) { // DialStream dials to a remote client entity with the given address. func (ce *Client) DialStream(ctx context.Context, addr Addr) (*Stream, error) { + + safeDialStream := func(dSes ClientSession) (*Stream, error) { + ce.dialMx.Lock() + str, err := dSes.DialStream(addr) + ce.dialMx.Unlock() + return str, err + } + entry, err := getClientEntry(ctx, ce.dc, addr.PK) if err != nil { return nil, err @@ -180,7 +189,7 @@ func (ce *Client) DialStream(ctx context.Context, addr Addr) (*Stream, error) { // See if we are already connected to a delegated server. for _, srvPK := range entry.Client.DelegatedServers { if dSes, ok := ce.ClientSession(ce.porter, srvPK); ok { - return dSes.DialStream(addr) + return safeDialStream(dSes) } } @@ -191,7 +200,7 @@ func (ce *Client) DialStream(ctx context.Context, addr Addr) (*Stream, error) { if err != nil { continue } - return dSes.DialStream(addr) + return safeDialStream(dSes) } return nil, ErrCannotConnectToDelegated diff --git a/vendor/github.com/SkycoinProject/dmsg/client_session.go b/vendor/github.com/SkycoinProject/dmsg/client_session.go index 71a8c43785..14b73bc2f5 100644 --- a/vendor/github.com/SkycoinProject/dmsg/client_session.go +++ b/vendor/github.com/SkycoinProject/dmsg/client_session.go @@ -24,7 +24,7 @@ func makeClientSession(entity *EntityCommon, porter *netutil.Porter, conn net.Co return cSes, nil } -// DialStream attempts to dial a stream to a remote client via the dsmg server that this session is connected to. +// DialStream attempts to dial a stream to a remote client via the dmsg server that this session is connected to. func (cs *ClientSession) DialStream(dst Addr) (dStr *Stream, err error) { if dStr, err = newInitiatingStream(cs); err != nil { return nil, err diff --git a/vendor/github.com/SkycoinProject/dmsg/dump.rdb b/vendor/github.com/SkycoinProject/dmsg/dump.rdb new file mode 100644 index 0000000000..d565348a4b Binary files /dev/null and b/vendor/github.com/SkycoinProject/dmsg/dump.rdb differ diff --git a/vendor/github.com/SkycoinProject/dmsg/errors.go b/vendor/github.com/SkycoinProject/dmsg/errors.go index b625842da8..7d4287b67f 100644 --- a/vendor/github.com/SkycoinProject/dmsg/errors.go +++ b/vendor/github.com/SkycoinProject/dmsg/errors.go @@ -5,42 +5,42 @@ import ( "sync" ) -// Entity Errors (10-19). +// Errors for dmsg discovery (1xx). var ( - ErrEntityClosed = NewError(10, "local entity closed", nil) - ErrSessionClosed = NewError(11, "local session closed", nil) - ErrCannotConnectToDelegated = NewError(12, "cannot connect to delegated server", nil) - ErrSessionHandshakeExtraBytes = NewError(13, "extra bytes received during session handshake", nil) + ErrDiscEntryNotFound = NewError(100, "discovery entry is not found", nil) + ErrDiscEntryIsNotServer = NewError(101, "discovery entry is not of server", nil) + ErrDiscEntryIsNotClient = NewError(102, "discovery entry is not of client", nil) + ErrDiscEntryHasNoDelegated = NewError(103, "discovery client entry has no delegated servers", nil) ) -// Errors for dmsg discovery (30-39). +// Entity Errors (2xx). var ( - ErrDiscEntryNotFound = NewError(30, "discovery entry is not found", nil) - ErrDiscEntryIsNotServer = NewError(31, "discovery entry is not of server", nil) - ErrDiscEntryIsNotClient = NewError(32, "discovery entry is not of client", nil) - ErrDiscEntryHasNoDelegated = NewError(33, "discovery client entry has no delegated servers", nil) + ErrEntityClosed = NewError(200, "local entity closed", nil) + ErrSessionClosed = NewError(201, "local session closed", nil) + ErrCannotConnectToDelegated = NewError(202, "cannot connect to delegated server", nil) + ErrSessionHandshakeExtraBytes = NewError(203, "extra bytes received during session handshake", nil) ) -// Errors for dial request/response (50-69). +// Errors for dial request/response (3xx). var ( - ErrReqInvalidSig = NewError(50, "request has invalid signature", nil) - ErrReqInvalidTimestamp = NewError(51, "request timestamp should be higher than last", nil) - ErrReqInvalidSrcPK = NewError(52, "request has invalid source public key", nil) - ErrReqInvalidDstPK = NewError(53, "request has invalid destination public key", nil) - ErrReqInvalidSrcPort = NewError(54, "request has invalid source port", nil) - ErrReqInvalidDstPort = NewError(55, "request has invalid destination port", nil) - ErrReqNoListener = NewError(56, "request has no associated listener", nil) - ErrReqNoSession = NewError(57, "request has no associated session on the dmsg server", nil) + ErrReqInvalidSig = NewError(300, "request has invalid signature", nil) + ErrReqInvalidTimestamp = NewError(301, "request timestamp should be higher than last", nil) + ErrReqInvalidSrcPK = NewError(302, "request has invalid source public key", nil) + ErrReqInvalidDstPK = NewError(303, "request has invalid destination public key", nil) + ErrReqInvalidSrcPort = NewError(304, "request has invalid source port", nil) + ErrReqInvalidDstPort = NewError(305, "request has invalid destination port", nil) + ErrReqNoListener = NewError(306, "request has no associated listener", nil) + ErrReqNoSession = NewError(307, "request has no associated session on the dmsg server", nil) - ErrDialRespInvalidSig = NewError(60, "response has invalid signature", nil) - ErrDialRespInvalidHash = NewError(61, "response has invalid hash of associated request", nil) - ErrDialRespNotAccepted = NewError(62, "response rejected associated request without reason", nil) + ErrDialRespInvalidSig = NewError(350, "response has invalid signature", nil) + ErrDialRespInvalidHash = NewError(351, "response has invalid hash of associated request", nil) + ErrDialRespNotAccepted = NewError(352, "response rejected associated request without reason", nil) ) -// Listener errors (80-89). +// Listener errors (4xx). var ( - ErrPortOccupied = NewError(80, "port already occupied", nil) - ErrAcceptChanMaxed = NewError(81, "listener accept chan maxed", nil) + ErrPortOccupied = NewError(400, "port already occupied", nil) + ErrAcceptChanMaxed = NewError(401, "listener accept chan maxed", nil) ) // NetworkErrorOptions provides 'timeout' and 'temporary' options for NetworkError. @@ -66,15 +66,15 @@ func (err NetworkError) Temporary() bool { return err.Opts.Temporary } var ( errFmt = "code %d - %s" - errMap = make(map[uint8]error) - codeMap = make(map[error]uint8) + errMap = make(map[uint16]error) + codeMap = make(map[error]uint16) errMx sync.RWMutex ) // NewError creates a new dmsg error. // - code '0' represents a miscellaneous error and is not saved in 'errMap'. // - netOpts is only needed if it needs to implement 'net.Error'. -func NewError(code uint8, msg string, netOpts *NetworkErrorOptions) error { +func NewError(code uint16, msg string, netOpts *NetworkErrorOptions) error { // No need to check errMap if code 0. if code != 0 { errMx.Lock() @@ -96,7 +96,7 @@ func NewError(code uint8, msg string, netOpts *NetworkErrorOptions) error { } // ErrorFromCode returns a saved error (if exists) from given error code. -func ErrorFromCode(code uint8) (bool, error) { +func ErrorFromCode(code uint16) (bool, error) { errMx.RLock() err, ok := errMap[code] errMx.RUnlock() @@ -104,7 +104,7 @@ func ErrorFromCode(code uint8) (bool, error) { } // CodeFromError returns code from a given error. -func CodeFromError(err error) uint8 { +func CodeFromError(err error) uint16 { errMx.RLock() code, ok := codeMap[err] errMx.RUnlock() diff --git a/vendor/github.com/SkycoinProject/dmsg/listener.go b/vendor/github.com/SkycoinProject/dmsg/listener.go index 8e25d4621b..dc4f5376ae 100644 --- a/vendor/github.com/SkycoinProject/dmsg/listener.go +++ b/vendor/github.com/SkycoinProject/dmsg/listener.go @@ -115,5 +115,8 @@ func (l *Listener) isClosed() bool { // Addr returns the listener's address. func (l *Listener) Addr() net.Addr { return l.addr } +// DmsgAddr returns the listener's address in as `dmsg.Addr`. +func (l *Listener) DmsgAddr() Addr { return l.addr } + // Type returns the stream type. func (l *Listener) Type() string { return Type } diff --git a/vendor/github.com/SkycoinProject/dmsg/types.go b/vendor/github.com/SkycoinProject/dmsg/types.go index 2851f72f73..d59fea1807 100644 --- a/vendor/github.com/SkycoinProject/dmsg/types.go +++ b/vendor/github.com/SkycoinProject/dmsg/types.go @@ -116,7 +116,7 @@ func (dr StreamDialRequest) Verify(lastTimestamp int64) error { type StreamDialResponse struct { ReqHash cipher.SHA256 // Hash of associated dial request. Accepted bool // Whether the request is accepted. - ErrCode uint8 // Check if not accepted. + ErrCode uint16 // Check if not accepted. NoiseMsg []byte Sig cipher.Sig // Signature of this DialRequest, signed with public key of receiving node. } diff --git a/vendor/golang.org/x/net/nettest/conntest.go b/vendor/golang.org/x/net/nettest/conntest.go index 0427987e7d..39cc6a631e 100644 --- a/vendor/golang.org/x/net/nettest/conntest.go +++ b/vendor/golang.org/x/net/nettest/conntest.go @@ -37,9 +37,9 @@ func TestConn(t *testing.T, mp MakePipe) { t.Run("WriteTimeout", func(t *testing.T) { timeoutWrapper(t, mp, testWriteTimeout) }) t.Run("PastTimeout", func(t *testing.T) { timeoutWrapper(t, mp, testPastTimeout) }) t.Run("PresentTimeout", func(t *testing.T) { timeoutWrapper(t, mp, testPresentTimeout) }) - //t.Run("FutureTimeout", func(t *testing.T) { timeoutWrapper(t, mp, testFutureTimeout) }) - //t.Run("CloseTimeout", func(t *testing.T) { timeoutWrapper(t, mp, testCloseTimeout) }) - //t.Run("ConcurrentMethods", func(t *testing.T) { timeoutWrapper(t, mp, testConcurrentMethods) }) + t.Run("FutureTimeout", func(t *testing.T) { timeoutWrapper(t, mp, testFutureTimeout) }) + t.Run("CloseTimeout", func(t *testing.T) { timeoutWrapper(t, mp, testCloseTimeout) }) + t.Run("ConcurrentMethods", func(t *testing.T) { timeoutWrapper(t, mp, testConcurrentMethods) }) } type connTester func(t *testing.T, c1, c2 net.Conn)