From 54eb229fd9ce1daf248e978c9c2fd3ecd6b4269e Mon Sep 17 00:00:00 2001 From: Alexandr Burdiyan Date: Fri, 15 Sep 2023 20:01:35 +0200 Subject: [PATCH] feat(backend): allow connecting using bare PeerIDs --- backend/daemon/api/networking/v1alpha/networking.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/backend/daemon/api/networking/v1alpha/networking.go b/backend/daemon/api/networking/v1alpha/networking.go index 581b2c9902..95b5dd17e6 100644 --- a/backend/daemon/api/networking/v1alpha/networking.go +++ b/backend/daemon/api/networking/v1alpha/networking.go @@ -32,6 +32,14 @@ func NewServer(node *future.ReadOnly[*mttnet.Node]) *Server { // Connect implements the Connect RPC method. func (srv *Server) Connect(ctx context.Context, in *networking.ConnectRequest) (*networking.ConnectResponse, error) { + // We want to support connecting to plain peer IDs, so we need to convert it into multiaddr. + if len(in.Addrs) == 1 { + addr := in.Addrs[0] + if !strings.Contains(addr, "/") { + in.Addrs[0] = "/p2p/" + addr + } + } + info, err := mttnet.AddrInfoFromStrings(in.Addrs...) if err != nil { return nil, status.Errorf(codes.InvalidArgument, "bad addrs: %v", err)