adding endpoint.
This commit is contained in:
@@ -23,8 +23,8 @@ func getNetworkInstance(opts *dialOptions) (net *netstack.Net, err error) {
|
||||
|
||||
deviceConf := "" +
|
||||
"public_key=" + opts.peerPubKey.HexString() + "\n" +
|
||||
"endpoint=" + opts.endpoint + "\n" +
|
||||
"allowed_ip=" + rpcEndpointIp + "/32\n" +
|
||||
"endpoint=" + opts.endpoint.String() + "\n" +
|
||||
"allowed_ip=" + opts.rpcEndpoint.Address() + "/32\n" +
|
||||
"persistent_keepalive_interval=" + strconv.Itoa(opts.keepAliveInterval) + "\n"
|
||||
|
||||
if err = dev.IpcSet(deviceConf); check(err) {
|
||||
|
||||
@@ -28,7 +28,12 @@ func DialContext(ctx context.Context, target string, opts ...DialOption) (conn *
|
||||
return nil, errors.New("Unsupported protocol. Only unix:// or noise://")
|
||||
}
|
||||
|
||||
dialOpts := &dialOptions{peerRPCIP: "192.168.37.2", mtu: 1420, endpoint: strings.TrimPrefix(target, "noise://")}
|
||||
dialOpts := &dialOptions{
|
||||
endpoint: EndpointString(target),
|
||||
rpcEndpoint: EndpointString("192.168.37.1:80"),
|
||||
peerRPCIP: "192.168.37.2",
|
||||
mtu: 1420,
|
||||
}
|
||||
|
||||
for _, opt := range opts {
|
||||
opt.apply(dialOpts)
|
||||
@@ -41,7 +46,7 @@ func DialContext(ctx context.Context, target string, opts ...DialOption) (conn *
|
||||
}
|
||||
|
||||
return grpc.DialContext(ctx,
|
||||
rpcEndpointIp+":"+rpcEndpointPort,
|
||||
dialOpts.rpcEndpoint.String(),
|
||||
grpc.WithTransportCredentials(insecure.NewCredentials()),
|
||||
grpc.WithContextDialer(func(ctx context.Context, address string) (net.Conn, error) {
|
||||
return network.DialContext(ctx, "tcp4", address)
|
||||
|
||||
@@ -3,7 +3,8 @@ package rpc
|
||||
// dialOptions configure a Dial call. dialOptions are set by the DialOption
|
||||
// values passed to Dial.
|
||||
type dialOptions struct {
|
||||
endpoint string
|
||||
endpoint Endpoint
|
||||
rpcEndpoint Endpoint
|
||||
key RPCPrivateKey
|
||||
peerPubKey RPCPublicKey
|
||||
peerRPCIP string
|
||||
|
||||
46
pkg/rpc/endpoint.go
Normal file
46
pkg/rpc/endpoint.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package rpc
|
||||
|
||||
import "strings"
|
||||
|
||||
type Endpoint string
|
||||
|
||||
func (e Endpoint) Address() string {
|
||||
|
||||
before, _, found := strings.Cut(string(e), ":")
|
||||
|
||||
if !found {
|
||||
return ""
|
||||
}
|
||||
|
||||
return before
|
||||
}
|
||||
|
||||
func (e Endpoint) Port() string {
|
||||
|
||||
_, after, found := strings.Cut(string(e), ":")
|
||||
|
||||
if !found {
|
||||
return ""
|
||||
}
|
||||
|
||||
return after
|
||||
}
|
||||
|
||||
func (e Endpoint) String() string {
|
||||
return string(e)
|
||||
}
|
||||
|
||||
func EndpointString(endpoint string) (ep Endpoint) {
|
||||
|
||||
_, after, found := strings.Cut(string(endpoint), "//")
|
||||
|
||||
if !found {
|
||||
ep = Endpoint(endpoint)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
ep = Endpoint(after)
|
||||
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user