From 870884effd21cc10dbed9c27665bdc9b066e9afd Mon Sep 17 00:00:00 2001 From: Steven Normore Date: Wed, 30 Aug 2023 18:49:12 -0400 Subject: [PATCH] Configure libp2p gossipsub WithDirectPeers --- pkg/authn/authn.pb.go | 6 +----- pkg/server/server.go | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/pkg/authn/authn.pb.go b/pkg/authn/authn.pb.go index b0d7b7c3..d8df5a16 100644 --- a/pkg/authn/authn.pb.go +++ b/pkg/authn/authn.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.28.1 -// protoc v4.23.3 +// protoc v4.24.2 // source: authn.proto package authn @@ -28,7 +28,6 @@ type Signature struct { unknownFields protoimpl.UnknownFields // Types that are assignable to Union: - // // *Signature_EcdsaCompact Union isSignature_Union `protobuf_oneof:"union"` } @@ -147,7 +146,6 @@ type PublicKey struct { Timestamp uint64 `protobuf:"varint,1,opt,name=timestamp,proto3" json:"timestamp,omitempty"` Signature *Signature `protobuf:"bytes,2,opt,name=signature,proto3,oneof" json:"signature,omitempty"` // Types that are assignable to Union: - // // *PublicKey_Secp256K1Uncompressed Union isPublicKey_Union `protobuf_oneof:"union"` } @@ -299,7 +297,6 @@ type ClientAuthRequest struct { unknownFields protoimpl.UnknownFields // Types that are assignable to Version: - // // *ClientAuthRequest_V1 Version isClientAuthRequest_Version `protobuf_oneof:"version"` } @@ -421,7 +418,6 @@ type ClientAuthResponse struct { unknownFields protoimpl.UnknownFields // Types that are assignable to Version: - // // *ClientAuthResponse_V1 Version isClientAuthResponse_Version `protobuf_oneof:"version"` } diff --git a/pkg/server/server.go b/pkg/server/server.go index 54a7a2bd..95b47dd8 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -138,7 +138,25 @@ func New(ctx context.Context, log *zap.Logger, options Options) (*Server, error) if !options.Relay.Disable { var wakurelayopts []pubsub.Option - wakurelayopts = append(wakurelayopts, pubsub.WithPeerExchange(true)) + directPeers := make([]peer.AddrInfo, 0, len(options.StaticNodes)) + for _, staticNode := range options.StaticNodes { + ma, err := multiaddr.NewMultiaddr(staticNode) + if err != nil { + s.log.Error("building multiaddr from static node addr", zap.Error(err)) + continue + } + pi, err := peer.AddrInfoFromP2pAddr(ma) + if err != nil { + s.log.Error("getting peer addr info from static node addr", zap.Error(err)) + continue + } + if pi == nil { + s.log.Error("static node peer addr is nil", zap.String("peer", staticNode)) + continue + } + directPeers = append(directPeers, *pi) + } + wakurelayopts = append(wakurelayopts, pubsub.WithPeerExchange(true), pubsub.WithDirectPeers(directPeers)) nodeOpts = append(nodeOpts, node.WithWakuRelayAndMinPeers(options.Relay.MinRelayPeersToPublish, wakurelayopts...)) }