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