|
9 | 9 | "github.com/qri-io/qri/p2p" |
10 | 10 | "github.com/qri-io/qri/repo" |
11 | 11 | "github.com/qri-io/qri/repo/profile" |
12 | | - // peer "gx/ipfs/QmXYjuNuxVzXKJCfWasQk1RqkhVLDM9jtUKhqc2WPQmFSB/go-libp2p-peer" |
| 12 | + |
| 13 | + peer "gx/ipfs/QmXYjuNuxVzXKJCfWasQk1RqkhVLDM9jtUKhqc2WPQmFSB/go-libp2p-peer" |
13 | 14 | ) |
14 | 15 |
|
15 | 16 | // PeerHandlers wraps a requests struct to interface with http.HandlerFunc |
@@ -50,18 +51,17 @@ func (h *PeerHandlers) PeerHandler(w http.ResponseWriter, r *http.Request) { |
50 | 51 | } |
51 | 52 | } |
52 | 53 |
|
53 | | -// TODO: add back connect endpoint |
54 | 54 | // ConnectToPeerHandler is the endpoint for explicitly connecting to a peer |
55 | | -// func (h *PeerHandlers) ConnectToPeerHandler(w http.ResponseWriter, r *http.Request) { |
56 | | -// switch r.Method { |
57 | | -// case "OPTIONS": |
58 | | -// util.EmptyOkHandler(w, r) |
59 | | -// case "GET": |
60 | | -// h.connectToPeerHandler(w, r) |
61 | | -// default: |
62 | | -// util.NotFoundHandler(w, r) |
63 | | -// } |
64 | | -// } |
| 55 | +func (h *PeerHandlers) ConnectToPeerHandler(w http.ResponseWriter, r *http.Request) { |
| 56 | + switch r.Method { |
| 57 | + case "OPTIONS": |
| 58 | + util.EmptyOkHandler(w, r) |
| 59 | + case "GET": |
| 60 | + h.connectToPeerHandler(w, r) |
| 61 | + default: |
| 62 | + util.NotFoundHandler(w, r) |
| 63 | + } |
| 64 | +} |
65 | 65 |
|
66 | 66 | // ConnectionsHandler is the endpoint for listing qri & IPFS connections |
67 | 67 | func (h *PeerHandlers) ConnectionsHandler(w http.ResponseWriter, r *http.Request) { |
@@ -120,21 +120,21 @@ func (h *PeerHandlers) namespaceHandler(w http.ResponseWriter, r *http.Request) |
120 | 120 |
|
121 | 121 | } |
122 | 122 |
|
123 | | -// TODO: add back connect endpoint |
124 | | -// func (h *PeerHandlers) connectToPeerHandler(w http.ResponseWriter, r *http.Request) { |
125 | | -// b58pid := r.URL.Path[len("/connect/"):] |
126 | | -// pid, err := peer.IDB58Decode(b58pid) |
127 | | -// if err != nil { |
128 | | -// util.WriteErrResponse(w, http.StatusBadRequest, err) |
129 | | -// return |
130 | | -// } |
131 | | - |
132 | | -// res := &profile.Profile{} |
133 | | -// if err := h.ConnectToPeer(&pid, res); err != nil { |
134 | | -// h.log.Infof("error connecting to peer: %s", err.Error()) |
135 | | -// util.WriteErrResponse(w, http.StatusInternalServerError, err) |
136 | | -// return |
137 | | -// } |
138 | | - |
139 | | -// util.WriteResponse(w, res) |
140 | | -// } |
| 123 | +func (h *PeerHandlers) connectToPeerHandler(w http.ResponseWriter, r *http.Request) { |
| 124 | + b58pid := r.URL.Path[len("/connect/"):] |
| 125 | + |
| 126 | + pid, err := peer.IDB58Decode(b58pid) |
| 127 | + if err != nil { |
| 128 | + util.WriteErrResponse(w, http.StatusBadRequest, err) |
| 129 | + return |
| 130 | + } |
| 131 | + |
| 132 | + res := &profile.Profile{} |
| 133 | + if err := h.ConnectToPeer(&pid, res); err != nil { |
| 134 | + h.log.Infof("error connecting to peer: %s", err.Error()) |
| 135 | + util.WriteErrResponse(w, http.StatusInternalServerError, err) |
| 136 | + return |
| 137 | + } |
| 138 | + |
| 139 | + util.WriteResponse(w, res) |
| 140 | +} |
0 commit comments