Skip to content
Snippets Groups Projects
Commit c0c3cfea authored by Jono Wenger's avatar Jono Wenger
Browse files

Standardize the IP config options by replacing ListeningAddress with...

Standardize the IP config options by replacing ListeningAddress with AddressOverride and by removing all gateway address flags so that the gateway address must be retrieved from gateway
parent 1243d35d
Branches
Tags
No related merge requests found
......@@ -125,6 +125,9 @@ node:
# Path where the list of node addresses is saved to.
# Optional field; defaults to "/opt/xxnetwork/node-logs/ipList.txt".
ipListOutput: "/opt/xxnetwork/node-logs/ipList.txt"
# If set, this address (host and port required) will be used for the node's
# public IP address instead of the automatically determined address. Optional.
addressOverride: ""
# Port that the Node will communicate on.
port: 42069
......@@ -140,13 +143,6 @@ gateways:
# Path to the self-signed TLS certificate for Gateway. Expects PEM format.
# Required field.
cert: "/opt/xxnetwork/creds/gateway-cert.crt"
# When set to true, the Node's public IP is used for Gateway. For use when the
# Gateway communicates to the Node via a local IP address.
# useNodeIp and AdvertisedIP cannot be set at the same time.
useNodeIp: false
# The address and port set here are used as the Gateway's public IP address.
# useNodeIp and AdvertisedIP cannot be set at the same time.
advertisedIP: ""
permissioning:
paths:
......
......@@ -10,6 +10,4 @@ package conf
// Contains Gateways config params
type Gateway struct {
Paths Paths
useNodeIp bool
advertisedIP string
}
......@@ -10,7 +10,7 @@ package conf
// Contains Node config params
type Node struct {
Paths Paths
ListeningAddress string
AddressOverride string
Port int
InterconnectPort int
}
......@@ -17,7 +17,7 @@ var nodeID = id.ID([33]byte{82, 253, 252, 7, 33, 130, 101, 79, 22, 63, 95, 15,
var ExpectedNode = Node{
Paths: ExpectedPaths,
ListeningAddress: "127.0.0.1",
AddressOverride: "",
Port: 80,
}
......
......@@ -9,7 +9,6 @@ package conf
import (
gorsa "crypto/rsa"
"fmt"
"github.com/pkg/errors"
jww "github.com/spf13/jwalterweatherman"
"github.com/spf13/viper"
......@@ -24,7 +23,9 @@ import (
"gitlab.com/xx_network/primitives/id/idf"
"gitlab.com/xx_network/primitives/ndf"
"gitlab.com/xx_network/primitives/utils"
"net"
"runtime"
"strconv"
"time"
)
......@@ -72,8 +73,7 @@ func NewParams(vip *viper.Viper) (*Params, error) {
params.RegistrationCode = vip.GetString("registrationCode")
require(params.RegistrationCode, "registrationCode")
vip.SetDefault("node.listeningAddress", "0.0.0.0")
params.Node.ListeningAddress = vip.GetString("node.listeningAddress")
params.Node.AddressOverride = vip.GetString("node.addressOverride")
params.Node.Port = vip.GetInt("node.Port")
if params.Node.Port == 0 {
jww.FATAL.Panic("Must specify a port to run on")
......@@ -145,13 +145,6 @@ func NewParams(vip *viper.Viper) (*Params, error) {
params.Metrics.Log = vip.GetString("metrics.log")
params.Gateway.useNodeIp = vip.GetBool("gateway.useNodeIp")
params.Gateway.advertisedIP = vip.GetString("gateway.advertisedIP")
if params.Gateway.useNodeIp && params.Gateway.advertisedIP != "" {
jww.FATAL.Panicf("Cannot set both gateway.useNodeIp and " +
"gateway.advertisedIP at the same time.")
}
params.DevMode = viper.GetBool("devMode")
return &params, nil
......@@ -186,7 +179,7 @@ func (p *Params) ConvertToDefinition() (*internal.Definition, error) {
}
}
def.Address = fmt.Sprintf("%s:%d", p.Node.ListeningAddress, p.Node.Port)
def.Address = net.JoinHostPort(p.Node.AddressOverride, strconv.Itoa(p.Node.Port))
def.InterconnectPort = p.Node.InterconnectPort
def.TlsCert = tlsCert
def.TlsKey = tlsKey
......@@ -305,8 +298,6 @@ func (p *Params) ConvertToDefinition() (*internal.Definition, error) {
def.GraphGenerator = services.NewGraphGenerator(p.GraphGen.minInputSize,
p.GraphGen.defaultNumTh, p.GraphGen.outputSize, p.GraphGen.outputThreshold)
def.Gateway.UseNodeIp = p.Gateway.useNodeIp
def.Gateway.AdvertisedIP = p.Gateway.advertisedIP
def.DevMode = p.DevMode
return def, nil
}
......
......@@ -130,10 +130,6 @@ type GW struct {
TlsCert []byte
// IP address of the gateway
Address string
// Toggles use of Node's IP address as Gateway's address in Permissioning.
UseNodeIp bool
// Replaces Gateway's IP address reported to Permissioning.
AdvertisedIP string
}
type MetricsHandler func(i *Instance, roundID id.Round) error
......@@ -35,7 +35,6 @@ import (
"gitlab.com/xx_network/crypto/signature/rsa"
"gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/utils"
"net"
"os"
"strings"
"sync"
......@@ -43,10 +42,6 @@ import (
"testing"
)
// The placeholder for the host in the Gateway address that is used to indicate
// to permissioning to replace it with the Node's host.
const gatewayReplaceIpPlaceholder = "CHANGE_TO_PUBLIC_IP"
type RoundErrBroadcastFunc func(host *connect.Host, message *mixmessages.RoundError) (*messages.Ack, error)
// Holds long-lived server state
......@@ -88,8 +83,6 @@ type Instance struct {
gatewayAddress string
gatewayVersion string
gatewayMutex sync.RWMutex
useNodeIpForGateway bool
gatewayAdvertisedIP string
serverVersion string
......@@ -126,8 +119,6 @@ func CreateServerInstance(def *Definition, makeImplementation func(*Instance) *n
panicWrapper: func(s string) {
jww.FATAL.Panic(s)
},
useNodeIpForGateway: def.Gateway.UseNodeIp,
gatewayAdvertisedIP: def.Gateway.AdvertisedIP,
serverVersion: version,
firstRun: &firstRun,
firstPoll: &firstPoll,
......@@ -455,47 +446,24 @@ func (i *Instance) GetGatewayData() (addr string, ver string) {
return i.gatewayAddress, i.gatewayVersion
}
// UpsertGatewayData saves the gateway address and version to the instance, if
// they differ. Panics if the gateway address is empty.
func (i *Instance) UpsertGatewayData(addr string, ver string) {
jww.TRACE.Printf("Upserting Gateway: %s, %s", addr, ver)
if addr == "" {
jww.FATAL.Panicf("Faild to upsert gateway data, gateway address is empty.")
}
i.gatewayMutex.Lock()
defer i.gatewayMutex.Unlock()
addr = i.getGatewayAdvertisedIP(addr)
jww.TRACE.Printf("Upserting Gateway: %s, %s", addr, ver)
if i.gatewayAddress != addr || i.gatewayVersion != ver {
(*i).gatewayAddress = addr
(*i).gatewayVersion = ver
}
}
// getGatewayAdvertisedIP returns the correct advertised IP for Gateway. If
// useNodeIpForGateway is set, then a placeholder with the Gateway's IP is
// returned. If gatewayAdvertisedIP is set, then it is returned. If neither is
// set, then the original Gateway IP is returned.
func (i *Instance) getGatewayAdvertisedIP(gatewayAddr string) string {
if gatewayAddr != "" {
if i.useNodeIpForGateway {
_, port, err := net.SplitHostPort(gatewayAddr)
if err != nil {
jww.FATAL.Panicf("Error parsing Gateway address %#v: %v", gatewayAddr, err)
}
addr := net.JoinHostPort(gatewayReplaceIpPlaceholder, port)
jww.TRACE.Printf("useNodeIpForGateway flag is set. Modified Gateway's "+
"address to %s", addr)
return addr
}
if i.gatewayAdvertisedIP != "" {
jww.TRACE.Printf("gatewayAdvertisedIP flag is set. Modified Gateway's "+
"address to %s", i.gatewayAdvertisedIP)
return i.gatewayAdvertisedIP
}
}
return gatewayAddr
}
/* TESTING FUNCTIONS */
func (i *Instance) OverridePhases(overrides map[int]phase.Phase) {
i.phaseOverrides = overrides
......@@ -584,8 +552,8 @@ func (i *Instance) ReportRemoteFailure(roundErr *mixmessages.RoundError) {
i.reportFailure(roundErr)
}
// Create a round error, pass the error over the chanel and update the state to ERROR state
// In situations that cause critical panic level errors.
// Create a round error, pass the error over the channel and update the state to
// ERROR state. In situations that cause critical panic level errors.
func (i *Instance) ReportRoundFailure(errIn error, nodeId *id.ID, roundId id.Round) {
//truncate the error if it is too long
......@@ -610,8 +578,8 @@ func (i *Instance) ReportRoundFailure(errIn error, nodeId *id.ID, roundId id.Rou
i.reportFailure(&roundErr)
}
// Create a round error, pass the error over the chanel and update the state to ERROR state
// In situations that cause critical panic level errors.
// Create a round error, pass the error over the channel and update the state to
// ERROR state. In situations that cause critical panic level errors.
func (i *Instance) reportFailure(roundErr *mixmessages.RoundError) {
i.errLck.Lock()
defer i.errLck.Unlock()
......
......@@ -402,72 +402,3 @@ func TestInstance_GetPhaseOverrides(t *testing.T) {
t.Error("Failed to get phase overrides set in instance")
}
}
// Tests that GetGatewayAdvertisedIP() returns the original gatewayAddress when
// neither useNodeIpForGateway nor gatewayAdvertisedIP are set.
func TestInstance_GetGatewayAdvertisedIP(t *testing.T) {
instance := Instance{
gatewayAddress: "0.0.0.0:22840",
}
testIP := instance.getGatewayAdvertisedIP(instance.gatewayAddress)
if testIP != instance.gatewayAddress {
t.Errorf("GetGatewayAdvertisedIP() did not return the correct address "+
"when no flags where set.\n\texpected: %v\n\treceived: %v",
instance.gatewayAddress, testIP)
}
}
// Tests that GetGatewayAdvertisedIP() returns the gatewayReplaceIpPlaceholder
// with the original gatewayAddress port when useNodeIpForGateway is set.
func TestInstance_GetGatewayAdvertisedIP_useNodeIpForGateway(t *testing.T) {
instance := Instance{
gatewayAddress: "0.0.0.0:22840",
useNodeIpForGateway: true,
}
expectedIP := gatewayReplaceIpPlaceholder + ":22840"
testIP := instance.getGatewayAdvertisedIP(instance.gatewayAddress)
if testIP != expectedIP {
t.Errorf("GetGatewayAdvertisedIP() did not return the correct address "+
"when useNodeIpForGateway was set.\n\texpected: %v\n\treceived: %v",
expectedIP, testIP)
}
}
// Tests that GetGatewayAdvertisedIP() returns the gatewayAdvertisedIP when it
// is set.
func TestInstance_GetGatewayAdvertisedIP_gatewayAdvertisedIP(t *testing.T) {
instance := Instance{
gatewayAddress: "0.0.0.0:22840",
gatewayAdvertisedIP: "192.168.1.1:22840",
}
testIP := instance.getGatewayAdvertisedIP(instance.gatewayAddress)
if testIP != instance.gatewayAdvertisedIP {
t.Errorf("GetGatewayAdvertisedIP() did not return the correct address "+
"when gatewayAdvertisedIP was set.\n\texpected: %v\n\treceived: %v",
instance.gatewayAdvertisedIP, testIP)
}
}
// Tests that GetGatewayAdvertisedIP() panics when useNodeIpForGateway is set
// and the provided Gateway address does not have a port.
func TestInstance_GetGatewayAdvertisedIP_useNodeIpForGateway_NoPort(t *testing.T) {
instance := Instance{
gatewayAddress: "0.0.0.0",
useNodeIpForGateway: true,
}
defer func() {
if r := recover(); r == nil {
t.Errorf("getGatewayAdvertisedIP() did not panic when no port was " +
"provided.")
}
}()
_ = instance.getGatewayAdvertisedIP(instance.gatewayAddress)
}
......@@ -32,24 +32,7 @@ func ReceivePoll(poll *mixmessages.ServerPoll, instance *internal.Instance,
res := mixmessages.ServerPollResponse{}
jww.TRACE.Printf("Gateway Info: %s, %s", poll.GatewayAddress,
poll.GatewayVersion)
// fixme: this is a hack. due to the interconnected web of server <-> permissioning polling
// and GW <-> server polling, we reach a deadlock state
// To elaborate: GW only sets its address AFTER polling server for an NDF and
// checking Connectivity w/ permissioning (GW needs to poll server to contact permissioning in the first place)
// so it sends an empty address to server until this is set
// However server needs GW's address BEFORE registering as it needs to provide valid addresses for the NDF
// Server does not provide an NDF to GW until it (server) has registered and polled permissioning
// Which means GW cannot get a response when it polls server and cannot move forward to setting its own address
// Therefore GW doesn't ever get it's address set, and server crashes when trying to parse an empty GW address
// fixme: Suggested solution: Generate a comm where server gets GW's address, and place that comm in RegisterNode
// Cannot upsert gateway data unless valid address is sent through the wire
if poll.GatewayAddress == "" {
poll.GatewayAddress = "1.2.3.4:11420"
}
// Form gateway address and put it into gateway data in instance
// Put gateway address and version into gateway data in instance
instance.UpsertGatewayData(poll.GatewayAddress, poll.GatewayVersion)
// Asynchronously indicate that gateway has successfully contacted
......
......@@ -134,6 +134,7 @@ func setupTests(t *testing.T, testState current.Activity) (internal.Instance, *p
Partial: &pb.NDFHash{Hash: fullHash1},
LastUpdate: 0,
Error: "",
GatewayAddress: "1.2.3.4:11420",
}
fullHash2, err := dataStructures.GenerateNDFHash(test2Ndf)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment