Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ func (c serveCmdConfig) Run() {
},
},
Addresses: relayAddresses,
LocalhostIP: viper.GetString("Relay.Interface.LocalhostIP"),
}

configRelay, err := peer.GetConfig(configRelayArgs)
Expand Down Expand Up @@ -598,7 +599,6 @@ func configureLocalhostForwarding(localhostAddr netip.Addr, s *stack.Stack) {
// Adds a rule to the start of a table chain.
func prependIPtableRule(table stack.Table, newRule stack.Rule, chain stack.Hook) (stack.Table) {
insertIndex := int(table.BuiltinChains[chain])
fmt.Printf("Inserting rule into index %d\n", insertIndex)
table.Rules = slices.Insert(table.Rules, insertIndex, newRule)

// Increment the later chain and underflow index pointers to account for the rule added to the Rules slice
Expand Down
91 changes: 57 additions & 34 deletions src/cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ type statusCmdConfig struct {
configFileE2EE string
}

// Represents one Server or Client in tree
type Node struct {
peerConfig peer.PeerConfig
relayConfig peer.Config
e2eeConfig peer.Config
children []*Node
interfaces []api.HostInterface
error string
}

// Defaults for status command.
// See root command for shared defaults.
var statusCmd = statusCmdConfig{
Expand Down Expand Up @@ -50,16 +60,6 @@ func init() {

// Run attempts to parse config files into a network diagram.
func (cc statusCmdConfig) Run() {
// Start building tree.
type Node struct {
peerConfig peer.PeerConfig
relayConfig peer.Config
e2eeConfig peer.Config
children []*Node
interfaces []api.HostInterface
error string
}

var err error

// Parse the relay and e2ee config files
Expand All @@ -81,32 +81,21 @@ func (cc statusCmdConfig) Run() {
nodes := make(map[string]Node)
var errorNodes []Node
e2ee_peer_list := client.e2eeConfig.GetPeers()
nodeChannel := make(chan Node)
for _, ep := range e2ee_peer_list {
relayConfig, e2eeConfig, err := api.ServerInfo(netip.AddrPortFrom(ep.GetApiAddr(), uint16(ApiPort)))
if err != nil {
errorNodes = append(errorNodes, Node{
peerConfig: ep,
error: err.Error(),
})
// Make all the API requests concurrently to speed things up
go cc.makeAPIRequests(nodeChannel, ep)
}

} else {
var interfaces []api.HostInterface
if cc.networkInfo {
interfaces, err = api.ServerInterfaces(netip.AddrPortFrom(ep.GetApiAddr(), uint16(ApiPort)))
if err != nil {
interfaces = append(interfaces, api.HostInterface{
Name: "ERROR: " + err.Error(),
})
}
}
// Don't need to do anything with values, just need to loop the same number of times
for range e2ee_peer_list {
responseNode := <- nodeChannel

nodes[relayConfig.GetPublicKey()] = Node{
peerConfig: ep,
relayConfig: relayConfig,
e2eeConfig: e2eeConfig,
interfaces: interfaces,
}
}
if responseNode.error == "" {
nodes[responseNode.relayConfig.GetPublicKey()] = responseNode
} else {
errorNodes = append(errorNodes, responseNode)
}
}

// Build tree by adding each relay node as a child.
Expand Down Expand Up @@ -167,6 +156,10 @@ func (cc statusCmdConfig) Run() {
api,
strings.Join(ips, ","),
)

if c.relayConfig.GetLocalhostIP() != "" {
nodeString += "\n lhost IP: " + c.relayConfig.GetLocalhostIP()
}

if cc.networkInfo {
nodeString += `
Expand All @@ -175,7 +168,7 @@ Network Interfaces:
-------------------
`
for _, ifx := range c.interfaces {
nodeString += fmt.Sprintf("%v:\n", ifx.Name)
nodeString += ifx.Name + "\n"
for _, a := range ifx.Addrs {
nodeString += strings.Repeat(" ", 2) + a.String() + "\n"
}
Expand Down Expand Up @@ -233,6 +226,36 @@ Network Interfaces:
}
}

func (cc statusCmdConfig) makeAPIRequests(ch chan<- Node, ep peer.PeerConfig) {
relayConfig, e2eeConfig, err := api.ServerInfo(netip.AddrPortFrom(ep.GetApiAddr(), uint16(ApiPort)))
if err != nil {
ch <- Node{
peerConfig: ep,
error: err.Error(),
}
return

} else {
var interfaces []api.HostInterface
if cc.networkInfo {
interfaces, err = api.ServerInterfaces(netip.AddrPortFrom(ep.GetApiAddr(), uint16(ApiPort)))
if err != nil {
interfaces = append(interfaces, api.HostInterface{
Name: "ERROR: " + err.Error(),
})
}
}

ch <- Node{
peerConfig: ep,
relayConfig: relayConfig,
e2eeConfig: e2eeConfig,
interfaces: interfaces,
}
return
}
}

func errorWrap(text string, lineWidth int) string {
words := strings.Fields(strings.TrimSpace(text))
if len(words) == 0 {
Expand Down
9 changes: 8 additions & 1 deletion src/peer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ func GetConfig(args ConfigArgs) (Config, error) {
}
}

if args.LocalhostIP != "" {
err = c.SetLocalhostIP(args.LocalhostIP)
if err != nil {
return Config{}, err
}
}

return c, nil
}

Expand Down Expand Up @@ -157,7 +164,6 @@ func ParseConfig(filename string) (c Config, err error) {
err = c.SetMTU(mtu)
case "localhostip":
err = c.SetLocalhostIP(value)
fmt.Println("LocalhostIP value parsed")
}
if err != nil {
return c, err
Expand Down Expand Up @@ -241,6 +247,7 @@ func (c *Config) UnmarshalJSON(b []byte) error {
c.config = tmp.Config
c.peers = tmp.Peers
c.addresses = tmp.Addresses
c.localhostIP = tmp.LocalhostIP

return nil
}
Expand Down
Loading