successful test of rpc client over unix sockets and tcp.
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
|||||||
"github.com/multiformats/go-multiaddr"
|
"github.com/multiformats/go-multiaddr"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
|
"github.com/tutorialedge/go-grpc-tutorial/chat"
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -90,6 +91,9 @@ var seedCmd = &cobra.Command{
|
|||||||
// We need to enable specific gRPC services here
|
// We need to enable specific gRPC services here
|
||||||
//srv := rpc.Server()
|
//srv := rpc.Server()
|
||||||
//helloworld.RegisterGreeterServer(srv, helloworld)
|
//helloworld.RegisterGreeterServer(srv, helloworld)
|
||||||
|
s := chat.Server{}
|
||||||
|
|
||||||
|
chat.RegisterChatServiceServer(rpc.Server(), &s)
|
||||||
|
|
||||||
log.I.Ln("starting rpc server")
|
log.I.Ln("starting rpc server")
|
||||||
|
|
||||||
|
|||||||
1
go.mod
1
go.mod
@@ -171,6 +171,7 @@ require (
|
|||||||
github.com/subosito/gotenv v1.4.2 // indirect
|
github.com/subosito/gotenv v1.4.2 // indirect
|
||||||
github.com/templexxx/cpu v0.0.1 // indirect
|
github.com/templexxx/cpu v0.0.1 // indirect
|
||||||
github.com/templexxx/xorsimd v0.1.1 // indirect
|
github.com/templexxx/xorsimd v0.1.1 // indirect
|
||||||
|
github.com/tutorialedge/go-grpc-tutorial v0.0.0-20200509091100-f8d1b5b15b01 // indirect
|
||||||
github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1 // indirect
|
github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1 // indirect
|
||||||
github.com/xanzy/ssh-agent v0.2.1 // indirect
|
github.com/xanzy/ssh-agent v0.2.1 // indirect
|
||||||
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect
|
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect
|
||||||
|
|||||||
2
go.sum
2
go.sum
@@ -1111,6 +1111,8 @@ github.com/templexxx/xorsimd v0.1.1 h1:Y4e8YgMx/4xRJO4G6lq0bSswfDCxbIrGu7KqM2ET5
|
|||||||
github.com/templexxx/xorsimd v0.1.1/go.mod h1:W+ffZz8jJMH2SXwuKu9WhygqBMbFnp14G2fqEr8qaNo=
|
github.com/templexxx/xorsimd v0.1.1/go.mod h1:W+ffZz8jJMH2SXwuKu9WhygqBMbFnp14G2fqEr8qaNo=
|
||||||
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
|
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
|
||||||
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
|
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
|
||||||
|
github.com/tutorialedge/go-grpc-tutorial v0.0.0-20200509091100-f8d1b5b15b01 h1:dVcYTEMB9QwRqslGxkvYGXI3fL7twjdbTTADm7J3TU8=
|
||||||
|
github.com/tutorialedge/go-grpc-tutorial v0.0.0-20200509091100-f8d1b5b15b01/go.mod h1:LBdTyeyzGK4jRGHXkC3z2BFf/Fml8peKISp1OtHDmvs=
|
||||||
github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc=
|
github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc=
|
||||||
github.com/urfave/cli v0.0.0-20171014202726-7bc6a0acffa5/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
|
github.com/urfave/cli v0.0.0-20171014202726-7bc6a0acffa5/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
|
||||||
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
|
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
|
||||||
|
|||||||
@@ -1,17 +1,21 @@
|
|||||||
package rpc
|
package rpc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"github.com/multiformats/go-multiaddr"
|
"github.com/multiformats/go-multiaddr"
|
||||||
"golang.zx2c4.com/wireguard/conn"
|
"golang.zx2c4.com/wireguard/conn"
|
||||||
"golang.zx2c4.com/wireguard/device"
|
"golang.zx2c4.com/wireguard/device"
|
||||||
"golang.zx2c4.com/wireguard/tun"
|
"golang.zx2c4.com/wireguard/tun"
|
||||||
"golang.zx2c4.com/wireguard/tun/netstack"
|
"golang.zx2c4.com/wireguard/tun/netstack"
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
"google.golang.org/grpc/credentials/insecure"
|
||||||
|
"net"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
DefaultClientIPAddr = netip.MustParseAddr("127.0.37.2")
|
DefaultClientIPAddr = netip.MustParseAddr("192.168.4.29")
|
||||||
)
|
)
|
||||||
|
|
||||||
type Peer struct {
|
type Peer struct {
|
||||||
@@ -75,5 +79,17 @@ func NewClient(config *ClientConfig) (*RPCClient, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//var conn *grpc.ClientConn
|
||||||
|
|
||||||
|
go grpc.Dial("unix:///tmp/indra.sock", grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||||
|
|
||||||
|
go grpc.DialContext(context.Background(),
|
||||||
|
deviceIP.String()+":80",
|
||||||
|
grpc.WithBlock(),
|
||||||
|
grpc.WithTransportCredentials(insecure.NewCredentials()),
|
||||||
|
grpc.WithContextDialer(func(ctx context.Context, address string) (net.Conn, error) {
|
||||||
|
return r.network.DialContext(ctx, "tcp4", address)
|
||||||
|
}))
|
||||||
|
|
||||||
return &r, nil
|
return &r, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ func CantStart() chan error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
deviceIP netip.Addr = netip.MustParseAddr("127.0.37.1")
|
deviceIP netip.Addr = netip.MustParseAddr("192.168.4.28")
|
||||||
devicePort int = 0
|
devicePort int = 0
|
||||||
deviceMTU int = 1420
|
deviceMTU int = 1420
|
||||||
)
|
)
|
||||||
@@ -88,7 +88,7 @@ func Start(ctx context.Context) {
|
|||||||
|
|
||||||
deviceConf := "" +
|
deviceConf := "" +
|
||||||
"public_key=" + peer_whitelist.HexString() + "\n" +
|
"public_key=" + peer_whitelist.HexString() + "\n" +
|
||||||
"allowed_ip=" + "127.0.37.2" + "/32\n"
|
"allowed_ip=" + DefaultClientIPAddr.String() + "/32\n"
|
||||||
|
|
||||||
if err = dev.IpcSet(deviceConf); check(err) {
|
if err = dev.IpcSet(deviceConf); check(err) {
|
||||||
startupErrors <- err
|
startupErrors <- err
|
||||||
@@ -108,13 +108,15 @@ func Start(ctx context.Context) {
|
|||||||
|
|
||||||
go server.Serve(unixSock)
|
go server.Serve(unixSock)
|
||||||
|
|
||||||
if tcpSock, err = network.ListenTCP(&net.TCPAddr{Port: devicePort}); check(err) {
|
if tcpSock, err = network.ListenTCPAddrPort(netip.AddrPortFrom(deviceIP, 80)); check(err) {
|
||||||
startupErrors <- err
|
startupErrors <- err
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
go server.Serve(tcpSock)
|
go server.Serve(tcpSock)
|
||||||
|
|
||||||
|
//network.ListenPing(netstack.PingAddrFromAddr(deviceIP))
|
||||||
|
|
||||||
isReady <- true
|
isReady <- true
|
||||||
|
|
||||||
select {
|
select {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package seed
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"git-indra.lan/indra-labs/indra/pkg/rpc"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/libp2p/go-libp2p"
|
"github.com/libp2p/go-libp2p"
|
||||||
@@ -75,6 +76,14 @@ func (srv *Server) Serve() (err error) {
|
|||||||
|
|
||||||
go metrics.HostStatus(ctx, srv.host)
|
go metrics.HostStatus(ctx, srv.host)
|
||||||
|
|
||||||
|
var client *rpc.RPCClient
|
||||||
|
|
||||||
|
if client, err = rpc.NewClient(rpc.DefaultClientConfig); check(err) {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
client.Start()
|
||||||
|
|
||||||
select {
|
select {
|
||||||
|
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
@@ -96,14 +105,6 @@ func New(config *Config) (*Server, error) {
|
|||||||
|
|
||||||
s.config = config
|
s.config = config
|
||||||
|
|
||||||
//var client *rpc.RPCClient
|
|
||||||
//
|
|
||||||
//if client, err = rpc.NewClient(rpc.DefaultClientConfig); check(err) {
|
|
||||||
// return nil, err
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//client.Start()
|
|
||||||
|
|
||||||
if s.host, err = libp2p.New(libp2p.Identity(config.PrivKey), libp2p.UserAgent(userAgent), libp2p.ListenAddrs(config.ListenAddresses...)); check(err) {
|
if s.host, err = libp2p.New(libp2p.Identity(config.PrivKey), libp2p.UserAgent(userAgent), libp2p.ListenAddrs(config.ListenAddresses...)); check(err) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user