coordinatorclient: validate network id

This commit is contained in:
Sergey Cherepanov 2023-07-17 19:30:04 +02:00
parent 27adabf1b9
commit 92d6ce1b3c
No known key found for this signature in database
GPG Key ID: 87F8EDE8FBDF637C

View File

@ -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))
}) })