Skip to content

Commit 2414277

Browse files
committed
fix: revert to raw api call for getting node id/multiaddrs
1 parent 90e52f0 commit 2414277

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

Diff for: router/user_api.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ func connectPeer(ctx *gin.Context, s store.P2PStore) {
162162
return
163163
}
164164

165-
err := s.ConnectPeer(ctx, a.Addrs...)
165+
err := s.ConnectPeer(ctx, a.Addresses...)
166166
if err != nil {
167167
ctx.JSON(http.StatusInternalServerError, ResponseError{
168168
Error: err.Error(),

Diff for: store/ipfs_store.go

+10-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package store
22

33
import (
44
"context"
5+
"encoding/json"
56
"log"
67
"net/http"
78

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

152153
func (s *IpfsStore) GetInfo(ctx context.Context) (*P2PNodeInfo, error) {
153-
n, err := s.ipfsApi.ID()
154+
resp, err := http.Post("http://localhost:5001/api/v0/id", "application/json", nil)
154155
if err != nil {
155156
return nil, err
156157
}
157-
return &P2PNodeInfo{
158-
ID: n.ID,
159-
Addrs: n.Addresses,
160-
}, nil
158+
defer resp.Body.Close()
159+
var ar P2PNodeInfo
160+
err = json.NewDecoder(resp.Body).Decode(&ar)
161+
if err != nil {
162+
return nil, err
163+
}
164+
165+
return &ar, nil
161166
}
162167

163168
func (s *IpfsStore) PinFile(ctx *gin.Context, c string) error {

Diff for: store/store.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ type P2PStore interface {
2020
}
2121

2222
type P2PNodeInfo struct {
23-
ID string `json:"id"`
24-
Addrs []string `json:"addrs"`
23+
ID string
24+
PublicKey string
25+
Addresses []string
26+
AgentVersion string
27+
ProtocolVersion string
2528
}

0 commit comments

Comments
 (0)