Compare commits
3 Commits
main
...
GO-1719-ne
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
940ad7d657 | ||
|
|
92d6ce1b3c | ||
|
|
27adabf1b9 |
@ -3,9 +3,11 @@ package coordinatorclient
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"github.com/anyproto/any-sync/app"
|
||||
"github.com/anyproto/any-sync/commonspace/object/tree/treechangeproto"
|
||||
"github.com/anyproto/any-sync/coordinator/coordinatorproto"
|
||||
"github.com/anyproto/any-sync/net/peer"
|
||||
"github.com/anyproto/any-sync/net/pool"
|
||||
"github.com/anyproto/any-sync/net/rpc/rpcerr"
|
||||
"github.com/anyproto/any-sync/nodeconf"
|
||||
@ -15,6 +17,11 @@ import (
|
||||
|
||||
const CName = "common.coordinator.coordinatorclient"
|
||||
|
||||
var (
|
||||
ErrPubKeyMissing = errors.New("peer pub key missing")
|
||||
ErrNetworkMismatched = errors.New("network mismatched")
|
||||
)
|
||||
|
||||
func New() CoordinatorClient {
|
||||
return new(coordinatorClient)
|
||||
}
|
||||
@ -145,6 +152,13 @@ func (c *coordinatorClient) doClient(ctx context.Context, f func(cl coordinatorp
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
pubKey, err := peer.CtxPubKey(p.Context())
|
||||
if err != nil {
|
||||
return ErrPubKeyMissing
|
||||
}
|
||||
if pubKey.Network() != c.nodeConf.Configuration().NetworkId {
|
||||
return ErrNetworkMismatched
|
||||
}
|
||||
return p.DoDrpc(ctx, func(conn drpc.Conn) error {
|
||||
return f(coordinatorproto.NewDRPCCoordinatorClient(conn))
|
||||
})
|
||||
|
||||
@ -21,6 +21,7 @@ var log = logger.NewNamed(CName)
|
||||
|
||||
var (
|
||||
ErrAddrsNotFound = errors.New("addrs for peer not found")
|
||||
ErrPeerIdMismatched = errors.New("peerId mismatched")
|
||||
)
|
||||
|
||||
func New() PeerService {
|
||||
@ -67,7 +68,7 @@ func (p *peerService) Dial(ctx context.Context, peerId string) (pr peer.Peer, er
|
||||
}
|
||||
|
||||
var mc transport.MultiConn
|
||||
log.InfoCtx(ctx, "dial", zap.String("peerId", peerId), zap.Strings("addrs", addrs))
|
||||
log.DebugCtx(ctx, "dial", zap.String("peerId", peerId), zap.Strings("addrs", addrs))
|
||||
for _, addr := range addrs {
|
||||
mc, err = p.yamux.Dial(ctx, addr)
|
||||
if err != nil {
|
||||
@ -79,6 +80,13 @@ func (p *peerService) Dial(ctx context.Context, peerId string) (pr peer.Peer, er
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
connPeerId, err := peer.CtxPeerId(mc.Context())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if connPeerId != peerId {
|
||||
return nil, ErrPeerIdMismatched
|
||||
}
|
||||
return peer.NewPeer(mc, p.server)
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user