Skip to content

Commit

Permalink
feat(backend): allow connecting using bare PeerIDs
Browse files Browse the repository at this point in the history
  • Loading branch information
burdiyan committed Sep 15, 2023
1 parent 9d82f19 commit 54eb229
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions backend/daemon/api/networking/v1alpha/networking.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 54eb229

Please sign in to comment.