hook jsonrpc peers subcribe into current federation

This commit is contained in:
Jeffrey Picard 2022-11-17 21:52:58 +00:00
parent 6a28d809c2
commit 0a5a7c7d33
3 changed files with 25 additions and 5 deletions

View file

@ -1,10 +1,15 @@
package server
import (
"context"
pb "github.com/lbryio/herald.go/protobuf/go"
log "github.com/sirupsen/logrus"
)
type PeersService struct{}
type PeersService struct {
Server *Server
}
type PeersSubscribeReq struct {
Ip string `json:"ip"`
@ -12,13 +17,28 @@ type PeersSubscribeReq struct {
Details []string `json:"details"`
}
type PeersSubscribeResp struct{}
type PeersSubscribeResp string
// Features is the json rpc endpoint for 'server.peers.subcribe'.
func (t *PeersService) Subscribe(req *PeersSubscribeReq, res **PeersSubscribeResp) error {
log.Println("PeersSubscribe")
ctx := context.Background()
var port = "50001"
// FIXME: Get the actual port from the request details
msg := &pb.ServerMessage{
Address: req.Ip,
Port: port,
}
peers, err := t.Server.PeerSubscribe(ctx, msg)
if err != nil {
log.Println(err)
*res = nil
return err
}
*res = (*PeersSubscribeResp)(&peers.Value)
return nil
}

View file

@ -135,7 +135,7 @@ fail1:
}
// Register "server.peers" handlers.
peersSvc := &PeersService{}
peersSvc := &PeersService{Server: s}
err = s1.RegisterTCPService(peersSvc, "server_peers")
if err != nil {
log.Errorf("RegisterTCPService: %v\n", err)

View file

@ -229,7 +229,7 @@ func (sm *sessionManager) addSession(conn net.Conn) *session {
}
// Register "server.peers" handlers.
peersSvc := &PeersService{}
peersSvc := &PeersService{Server: sm.server}
err = s1.RegisterName("server.peers", peersSvc)
if err != nil {
log.Errorf("RegisterName: %v\n", err)