-
Notifications
You must be signed in to change notification settings - Fork 0
/
rpc.go
34 lines (27 loc) · 815 Bytes
/
rpc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package p2p
import (
"github.com/libp2p/go-libp2p-core/host"
"github.com/libp2p/go-libp2p-core/protocol"
gorpc "github.com/libp2p/go-libp2p-gorpc"
"github.com/quantosnetwork/karod/services"
)
const P2PRpcPrefix protocol.ID = "/quantos/p2p/rpc/1.0.0"
type P2PRpc struct {
host *gorpc.Server
client *gorpc.Client
localClient *gorpc.Client
}
func (prpc *P2PRpc) New(h host.Host) {
prpc.host = gorpc.NewServer(h, P2PRpcPrefix)
prpc.localClient = gorpc.NewClientWithServer(h, P2PRpcPrefix, prpc.host)
}
func (prpc *P2PRpc) RegisterServices(repo *services.ServiceRepository) (err error) {
for _, elem := range repo.Services {
// We register all services in the ServiceRepository by Name
err = prpc.host.RegisterName(elem.Name(), elem)
if err != nil {
return err
}
}
return nil
}