Skip to content

Commit

Permalink
Display port forwarding hint in case of outbound and public ip mismatch
Browse files Browse the repository at this point in the history
  • Loading branch information
tadovas committed Jul 12, 2018
1 parent 4c52040 commit d1d5d37
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 13 deletions.
18 changes: 5 additions & 13 deletions cmd/commands/server/command_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type Command struct {

vpnServer openvpn.Process
checkOpenvpn func() error
openvpnServiceAddress func() (string, error)
protocol string
proposalAnnouncementStopped *sync.WaitGroup
}
Expand All @@ -75,11 +76,6 @@ func (cmd *Command) Start() (err error) {
cmd.dialogWaiter = cmd.dialogWaiterFactory(providerID)
providerContact, err := cmd.dialogWaiter.Start()

publicIP, err := cmd.ipResolver.GetPublicIP()
if err != nil {
return err
}

// if for some reason we will need truly external IP, use GetPublicIP()
outboundIP, err := cmd.ipResolver.GetOutboundIP()
if err != nil {
Expand Down Expand Up @@ -110,16 +106,12 @@ func (cmd *Command) Start() (err error) {
return err
}

if outboundIP != publicIP {
log.Infof(
`It seems that publicaly visible ip: [%s] does not match your local machines ip: [%s].
You should probaly need to do port forwarding on your router.`,
publicIP,
outboundIP,
)
openvpnServiceAddress, err := cmd.openvpnServiceAddress()
if err != nil {
return err
}

sessionManager := cmd.sessionManagerFactory(primitives, publicIP)
sessionManager := cmd.sessionManagerFactory(primitives, openvpnServiceAddress)

dialogHandler := session.NewDialogHandler(proposal.ID, sessionManager)
if err := cmd.dialogWaiter.ServeDialogs(dialogHandler); err != nil {
Expand Down
27 changes: 27 additions & 0 deletions cmd/commands/server/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
package server

import (
"fmt"
log "github.com/cihub/seelog"
"github.com/ethereum/go-ethereum/accounts/keystore"
identity_handler "github.com/mysterium/node/cmd/commands/server/identity"
"github.com/mysterium/node/communication"
Expand Down Expand Up @@ -137,6 +139,31 @@ func NewCommandWith(
checkOpenvpn: func() error {
return openvpn.CheckOpenvpnBinary(options.OpenvpnBinary)
},
openvpnServiceAddress: func() (string, error) {
publicIP, err := ipResolver.GetPublicIP()
if err != nil {
return "", err
}

outboundIP, err := ipResolver.GetOutboundIP()
if err != nil {
return "", err
}

if publicIP != outboundIP {
forwardInfo := fmt.Sprintf("%s:%v -> %s:%v", publicIP, options.OpenvpnPort, outboundIP, options.OpenvpnPort)
log.Warnf(
`WARNING: It seems that publicaly visible ip: [%s] does not match your local machines ip: [%s].
You should probaly need to do port forwarding on your router: %s.`,
publicIP,
outboundIP,
forwardInfo,
)

}

return publicIP, nil
},
protocol: options.Protocol,
proposalAnnouncementStopped: &sync.WaitGroup{},
}
Expand Down

0 comments on commit d1d5d37

Please sign in to comment.