refactor handshake err
This commit is contained in:
parent
d8ed9f9307
commit
24395ec7bf
@ -19,13 +19,13 @@ const (
|
||||
)
|
||||
|
||||
type HandshakeError struct {
|
||||
err error
|
||||
Err error
|
||||
e handshakeproto.Error
|
||||
}
|
||||
|
||||
func (he HandshakeError) Error() string {
|
||||
if he.err != nil {
|
||||
return he.err.Error()
|
||||
if he.Err != nil {
|
||||
return he.Err.Error()
|
||||
}
|
||||
return he.e.String()
|
||||
}
|
||||
@ -34,7 +34,7 @@ var (
|
||||
ErrUnexpectedPayload = HandshakeError{e: handshakeproto.Error_UnexpectedPayload}
|
||||
ErrDeadlineExceeded = HandshakeError{e: handshakeproto.Error_DeadlineExceeded}
|
||||
ErrInvalidCredentials = HandshakeError{e: handshakeproto.Error_InvalidCredentials}
|
||||
ErrPeerDeclinedCredentials = HandshakeError{err: errors.New("remote peer declined the credentials")}
|
||||
ErrPeerDeclinedCredentials = HandshakeError{Err: errors.New("remote peer declined the credentials")}
|
||||
ErrSkipVerifyNotAllowed = HandshakeError{e: handshakeproto.Error_SkipVerifyNotAllowed}
|
||||
ErrUnexpected = HandshakeError{e: handshakeproto.Error_Unexpected}
|
||||
|
||||
|
||||
@ -336,7 +336,7 @@ func TestIncomingHandshake(t *testing.T) {
|
||||
require.Equal(t, handshakeproto.Error_IncompatibleVersion, msg.ack.Error)
|
||||
|
||||
res := <-handshakeResCh
|
||||
require.EqualError(t, res.err, ErrIncompatibleVersion.Error())
|
||||
assert.Equal(t, res.err, ErrIncompatibleVersion)
|
||||
})
|
||||
t.Run("write cred instead ack", func(t *testing.T) {
|
||||
c1, c2 := newConnPair(t)
|
||||
|
||||
@ -16,19 +16,6 @@ import (
|
||||
"net"
|
||||
)
|
||||
|
||||
type HandshakeError struct {
|
||||
remoteAddr string
|
||||
err error
|
||||
}
|
||||
|
||||
func (he HandshakeError) RemoteAddr() string {
|
||||
return he.remoteAddr
|
||||
}
|
||||
|
||||
func (he HandshakeError) Error() string {
|
||||
return he.err.Error()
|
||||
}
|
||||
|
||||
const CName = "common.net.secure"
|
||||
|
||||
var log = logger.NewNamed(CName)
|
||||
@ -91,18 +78,14 @@ func (s *secureService) Name() (name string) {
|
||||
func (s *secureService) SecureInbound(ctx context.Context, conn net.Conn) (cctx context.Context, sc sec.SecureConn, err error) {
|
||||
sc, err = s.p2pTr.SecureInbound(ctx, conn, "")
|
||||
if err != nil {
|
||||
return nil, nil, HandshakeError{
|
||||
remoteAddr: conn.RemoteAddr().String(),
|
||||
err: err,
|
||||
return nil, nil, handshake.HandshakeError{
|
||||
Err: err,
|
||||
}
|
||||
}
|
||||
|
||||
identity, err := handshake.IncomingHandshake(ctx, sc, s.inboundChecker)
|
||||
if err != nil {
|
||||
return nil, nil, HandshakeError{
|
||||
remoteAddr: conn.RemoteAddr().String(),
|
||||
err: err,
|
||||
}
|
||||
return nil, nil, err
|
||||
}
|
||||
cctx = context.Background()
|
||||
cctx = peer.CtxWithPeerId(cctx, sc.RemotePeer().String())
|
||||
@ -113,7 +96,7 @@ func (s *secureService) SecureInbound(ctx context.Context, conn net.Conn) (cctx
|
||||
func (s *secureService) SecureOutbound(ctx context.Context, conn net.Conn) (sec.SecureConn, error) {
|
||||
sc, err := s.p2pTr.SecureOutbound(ctx, conn, "")
|
||||
if err != nil {
|
||||
return nil, HandshakeError{err: err, remoteAddr: conn.RemoteAddr().String()}
|
||||
return nil, handshake.HandshakeError{Err: err}
|
||||
}
|
||||
peerId := sc.RemotePeer().String()
|
||||
confTypes := s.nodeconf.GetLast().NodeTypes(peerId)
|
||||
@ -126,7 +109,7 @@ func (s *secureService) SecureOutbound(ctx context.Context, conn net.Conn) (sec.
|
||||
// ignore identity for outgoing connection because we don't need it at this moment
|
||||
_, err = handshake.OutgoingHandshake(ctx, sc, checker)
|
||||
if err != nil {
|
||||
return nil, HandshakeError{err: err, remoteAddr: conn.RemoteAddr().String()}
|
||||
return nil, err
|
||||
}
|
||||
return sc, nil
|
||||
}
|
||||
|
||||
@ -73,9 +73,9 @@ func TestHandshakeIncompatibleVersion(t *testing.T) {
|
||||
fxC := newFixture(t, nc, nc.GetAccountService(1), 1)
|
||||
defer fxC.Finish(t)
|
||||
_, err := fxC.SecureOutbound(ctx, cc)
|
||||
require.EqualError(t, err, handshake.ErrIncompatibleVersion.Error())
|
||||
require.Equal(t, handshake.ErrIncompatibleVersion, err)
|
||||
res := <-resCh
|
||||
require.EqualError(t, res.err, handshake.ErrIncompatibleVersion.Error())
|
||||
require.Equal(t, handshake.ErrIncompatibleVersion, res.err)
|
||||
}
|
||||
|
||||
func newFixture(t *testing.T, nc *testnodeconf.Config, acc accountservice.Service, protoVersion uint32) *fixture {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user