Skip to content

Commit

Permalink
fix: revert to raw api call for getting node id/multiaddrs
Browse files Browse the repository at this point in the history
  • Loading branch information
govi218 committed Feb 7, 2023
1 parent 90e52f0 commit 2414277
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion router/user_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func connectPeer(ctx *gin.Context, s store.P2PStore) {
return
}

err := s.ConnectPeer(ctx, a.Addrs...)
err := s.ConnectPeer(ctx, a.Addresses...)
if err != nil {
ctx.JSON(http.StatusInternalServerError, ResponseError{
Error: err.Error(),
Expand Down
15 changes: 10 additions & 5 deletions store/ipfs_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package store

import (
"context"
"encoding/json"
"log"
"net/http"

Expand Down Expand Up @@ -150,14 +151,18 @@ func (s *IpfsStore) List(ctx context.Context) ([]model.File, error) {
}

func (s *IpfsStore) GetInfo(ctx context.Context) (*P2PNodeInfo, error) {
n, err := s.ipfsApi.ID()
resp, err := http.Post("http://localhost:5001/api/v0/id", "application/json", nil)
if err != nil {
return nil, err
}
return &P2PNodeInfo{
ID: n.ID,
Addrs: n.Addresses,
}, nil
defer resp.Body.Close()
var ar P2PNodeInfo
err = json.NewDecoder(resp.Body).Decode(&ar)
if err != nil {
return nil, err
}

return &ar, nil
}

func (s *IpfsStore) PinFile(ctx *gin.Context, c string) error {
Expand Down
7 changes: 5 additions & 2 deletions store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ type P2PStore interface {
}

type P2PNodeInfo struct {
ID string `json:"id"`
Addrs []string `json:"addrs"`
ID string
PublicKey string
Addresses []string
AgentVersion string
ProtocolVersion string
}

0 comments on commit 2414277

Please sign in to comment.