Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into lint-warns
Browse files Browse the repository at this point in the history
# Conflicts:
#	connection/engine.go
  • Loading branch information
braginini committed May 19, 2021
2 parents 84c6eb5 + 635cd22 commit f0048d1
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
7 changes: 4 additions & 3 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ type Config struct {
Peers []connection.Peer
StunTurnURLs []*ice.URL
// host:port of the signal server
SignalAddr string
WgAddr string
WgIface string
SignalAddr string
WgAddr string
WgIface string
IFaceBlackList []string
}

//Write writes configPath to a file
Expand Down
6 changes: 5 additions & 1 deletion cmd/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ var (
//todo proper close handling
defer func() { signalClient.Close() }()

engine := connection.NewEngine(signalClient, config.StunTurnURLs, config.WgIface, config.WgAddr)
iFaceBlackList := make(map[string]struct{})
for i := 0; i < len(config.IFaceBlackList); i += 2 {
iFaceBlackList[config.IFaceBlackList[i]] = struct{}{}
}
engine := connection.NewEngine(signalClient, config.StunTurnURLs, config.WgIface, config.WgAddr, iFaceBlackList)

err = engine.Start(myKey, config.Peers)
if err != nil {
Expand Down
11 changes: 10 additions & 1 deletion connection/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ type ConnConfig struct {
RemoteWgKey wgtypes.Key

StunTurnURLS []*ice.URL

iFaceBlackList map[string]struct{}
}

// IceCredentials ICE protocol credentials struct
Expand Down Expand Up @@ -93,6 +95,13 @@ func (conn *Connection) Open(timeout time.Duration) error {
a, err := ice.NewAgent(&ice.AgentConfig{
NetworkTypes: []ice.NetworkType{ice.NetworkTypeUDP4},
Urls: conn.Config.StunTurnURLS,
InterfaceFilter: func(s string) bool {
if conn.Config.iFaceBlackList == nil {
return true
}
_, ok := conn.Config.iFaceBlackList[s]
return !ok
},
})
conn.agent = a

Expand Down Expand Up @@ -289,7 +298,7 @@ func (conn *Connection) listenOnConnectionStateChanges() error {
log.Errorf("failed selecting active ICE candidate pair %s", err)
return
}
log.Debugf("closed to peer %s via selected candidate pair %s", conn.Config.RemoteWgKey.String(), pair)
log.Infof("will connect to peer %s via a selected connnection candidate pair %s", conn.Config.RemoteWgKey.String(), pair)
} else if state == ice.ConnectionStateDisconnected || state == ice.ConnectionStateFailed {
// todo do we really wanna have a connection restart within connection itself? Think of moving it outside
err := conn.Close()
Expand Down
7 changes: 6 additions & 1 deletion connection/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ type Engine struct {
wgIface string
// Wireguard local address
wgIP string
// Network Interfaces to ignore
iFaceBlackList map[string]struct{}
}

// Peer is an instance of the Connection Peer
Expand All @@ -33,13 +35,15 @@ type Peer struct {
}

// NewEngine creates a new Connection Engine
func NewEngine(signal *signal.Client, stunsTurns []*ice.URL, wgIface string, wgAddr string) *Engine {
func NewEngine(signal *signal.Client, stunsTurns []*ice.URL, wgIface string, wgAddr string,
iFaceBlackList map[string]struct{}) *Engine {
return &Engine{
stunsTurns: stunsTurns,
signal: signal,
wgIface: wgIface,
wgIP: wgAddr,
conns: map[string]*Connection{},
iFaceBlackList: iFaceBlackList,
}
}

Expand Down Expand Up @@ -113,6 +117,7 @@ func (e *Engine) openPeerConnection(wgPort int, myKey wgtypes.Key, peer Peer) (*
WgKey: myKey,
RemoteWgKey: remoteKey,
StunTurnURLS: e.stunsTurns,
iFaceBlackList: e.iFaceBlackList,
}

signalOffer := func(uFrag string, pwd string) error {
Expand Down

0 comments on commit f0048d1

Please sign in to comment.