protect full node connection
This commit is contained in:
parent
e155eb9fa3
commit
ca46a79144
@ -4,6 +4,10 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/libp2p/go-libp2p-core/network"
|
||||||
|
|
||||||
|
"github.com/libp2p/go-libp2p-core/peer"
|
||||||
|
|
||||||
"github.com/filecoin-project/lotus/api/v1api"
|
"github.com/filecoin-project/lotus/api/v1api"
|
||||||
|
|
||||||
logging "github.com/ipfs/go-log/v2"
|
logging "github.com/ipfs/go-log/v2"
|
||||||
@ -21,16 +25,25 @@ type Libp2pMeshCreator struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (mc Libp2pMeshCreator) Connect(ctx context.Context) error {
|
func (mc Libp2pMeshCreator) Connect(ctx context.Context) error {
|
||||||
addrs, err := mc.fullnodeApi.NetAddrsListen(ctx)
|
faddrs, err := mc.fullnodeApi.NetAddrsListen(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := mc.idxProvHost.Connect(ctx, addrs); err != nil {
|
// if we already have a connection to the full node, there's nothing to do here
|
||||||
|
if mc.idxProvHost.Network().Connectedness(faddrs.ID) == network.Connected {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// otherwise, connect to the full node, ask it to protect the connection and protect the connection on our end too
|
||||||
|
if err := mc.idxProvHost.Connect(ctx, faddrs); err != nil {
|
||||||
return fmt.Errorf("failed to connect index provider host with the full node: %w", err)
|
return fmt.Errorf("failed to connect index provider host with the full node: %w", err)
|
||||||
}
|
}
|
||||||
mc.idxProvHost.ConnManager().Protect(addrs.ID, "markets")
|
mc.idxProvHost.ConnManager().Protect(faddrs.ID, "markets")
|
||||||
log.Debugw("successfully connected to full node", "fullNodeInfo", addrs.String())
|
mc.fullnodeApi.NetProtectAdd(ctx, []peer.ID{mc.idxProvHost.ID()})
|
||||||
|
|
||||||
|
log.Debugw("successfully connected to full node and asked it protect indexer provider peer conn", "fullNodeInfo", faddrs.String(),
|
||||||
|
"idxProviderPeerId", mc.idxProvHost.ID())
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user