Skip to content

Commit

Permalink
Merge pull request #110 from Kifen/listen-stcp
Browse files Browse the repository at this point in the history
Listen on STCP by default
  • Loading branch information
jdknives authored Jan 7, 2020
2 parents d9a73f4 + a0efeda commit bc8de0c
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions cmd/skywire-cli/commands/node/gen-config.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package node

import (
"errors"
"fmt"
"net"
"path/filepath"
"time"

Expand Down Expand Up @@ -84,6 +86,13 @@ func defaultConfig() *visor.Config {
conf.Node.StaticPubKey = pk
conf.Node.StaticSecKey = sk

lIPaddr, err := getLocalIPAddress()
if err != nil {
log.Warn(err)
}

conf.STCP.LocalAddr = lIPaddr

if testenv {
conf.Messaging.Discovery = skyenv.TestDmsgDiscAddr
} else {
Expand Down Expand Up @@ -184,3 +193,19 @@ func defaultSkysocksClientConfig() visor.AppConfig {
Port: routing.Port(skyenv.SkysocksClientPort),
}
}

func getLocalIPAddress() (string, error) {
addrs, err := net.InterfaceAddrs()
if err != nil {
return "", err
}

for _, a := range addrs {
if ipnet, ok := a.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
if ipnet.IP.To4() != nil {
return ipnet.IP.String() + ":7777", nil
}
}
}
return "", errors.New("could not find local IP address")
}

0 comments on commit bc8de0c

Please sign in to comment.