Protect index provider peer ID before connecting to full node
Add the peer ID of index provider host to the list of protected peers before connecting to full node. Otherwise, it is possible for the connection to be reset by full node before we reach the line that adds the ID to list of protected peers via JsonRPC API. Relates to: - https://github.com/filecoin-project/index-provider/issues/177
This commit is contained in:
parent
1bf7e6a408
commit
f15a1edbf2
@ -23,22 +23,28 @@ type Libp2pMeshCreator struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (mc Libp2pMeshCreator) Connect(ctx context.Context) error {
|
func (mc Libp2pMeshCreator) Connect(ctx context.Context) error {
|
||||||
|
|
||||||
|
// Add the index provider's host ID to list of protected peers first, before any attempt to
|
||||||
|
// connect to full node.
|
||||||
|
idxProvID := mc.idxProvHost.ID()
|
||||||
|
if err := mc.fullnodeApi.NetProtectAdd(ctx, []peer.ID{idxProvID}); err != nil {
|
||||||
|
return fmt.Errorf("failed to call NetProtectAdd on the full node, err: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
faddrs, err := mc.fullnodeApi.NetAddrsListen(ctx)
|
faddrs, err := mc.fullnodeApi.NetAddrsListen(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to fetch full node listen addrs, err: %w", err)
|
return fmt.Errorf("failed to fetch full node listen addrs, err: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// otherwise, connect to the full node, ask it to protect the connection and protect the connection on our end too
|
// Connect to the full node, ask it to protect the connection and protect the connection on
|
||||||
|
// markets end too.
|
||||||
if err := mc.idxProvHost.Connect(ctx, faddrs); err != nil {
|
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(faddrs.ID, "index-provider-gossipsub")
|
mc.idxProvHost.ConnManager().Protect(faddrs.ID, "index-provider-gossipsub")
|
||||||
if err := mc.fullnodeApi.NetProtectAdd(ctx, []peer.ID{mc.idxProvHost.ID()}); err != nil {
|
|
||||||
return fmt.Errorf("failed to call NetProtectAdd on the full node, err: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Debugw("successfully connected to full node and asked it protect indexer provider peer conn", "fullNodeInfo", faddrs.String(),
|
log.Debugw("successfully connected to full node and asked it protect indexer provider peer conn", "fullNodeInfo", faddrs.String(),
|
||||||
"idxProviderPeerId", mc.idxProvHost.ID())
|
"idxProviderPeerId", idxProvID)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user