From 2337c3d84d01625ee48daf1cb7df1775e393ebb3 Mon Sep 17 00:00:00 2001 From: mlsmaycon Date: Sat, 15 May 2021 15:05:15 +0500 Subject: [PATCH 1/9] fix doc and lint warns for iface package --- iface/iface.go | 20 ++++++++++++++------ iface/iface_darwin.go | 6 +++--- iface/iface_linux.go | 6 +++--- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/iface/iface.go b/iface/iface.go index 85b93e967d7..27fbbec96f0 100644 --- a/iface/iface.go +++ b/iface/iface.go @@ -61,7 +61,7 @@ func Create(iface string, address string) error { return nil } -// Extends the functionality of Configure(iface string, privateKey string) by generating a new Wireguard private key +// ConfigureWithKeyGen Extends the functionality of Configure(iface string, privateKey string) by generating a new Wireguard private key func ConfigureWithKeyGen(iface string) (*wgtypes.Key, error) { key, err := wgtypes.GeneratePrivateKey() if err != nil { @@ -70,7 +70,7 @@ func ConfigureWithKeyGen(iface string) (*wgtypes.Key, error) { return &key, Configure(iface, key.String()) } -// Configures a Wireguard interface +// Configure configures a Wireguard interface // The interface must exist before calling this method (e.g. call interface.Create() before) func Configure(iface string, privateKey string) error { @@ -100,6 +100,7 @@ func Configure(iface string, privateKey string) error { return nil } +// GetListenPort returns the listening port of the Wireguard endpoint func GetListenPort(iface string) (*int, error) { log.Debugf("getting Wireguard listen port of interface %s", iface) @@ -119,7 +120,7 @@ func GetListenPort(iface string) (*int, error) { return &d.ListenPort, nil } -// Updates a Wireguard interface listen port +// UpdateListenPort updates a Wireguard interface listen port func UpdateListenPort(iface string, newPort int) error { log.Debugf("updating Wireguard listen port of interface %s, new port %d", iface, newPort) @@ -156,7 +157,7 @@ func ifname(n string) []byte { return b } -// Updates existing Wireguard Peer or creates a new one if doesn't exist +// UpdatePeer updates existing Wireguard Peer or creates a new one if doesn't exist // Endpoint is optional func UpdatePeer(iface string, peerKey string, allowedIps string, keepAlive time.Duration, endpoint string) error { @@ -181,7 +182,9 @@ func UpdatePeer(iface string, peerKey string, allowedIps string, keepAlive time. } peerKeyParsed, err := wgtypes.ParseKey(peerKey) - + if err != nil { + return err + } peers := make([]wgtypes.PeerConfig, 0) peer := wgtypes.PeerConfig{ PublicKey: peerKeyParsed, @@ -207,7 +210,7 @@ func UpdatePeer(iface string, peerKey string, allowedIps string, keepAlive time. return nil } -// Updates a Wireguard interface Peer with the new endpoint +// UpdatePeerEndpoint updates a Wireguard interface Peer with the new endpoint // Used when NAT hole punching was successful and an update of the remote peer endpoint is required func UpdatePeerEndpoint(iface string, peerKey string, newEndpoint string) error { @@ -233,6 +236,9 @@ func UpdatePeerEndpoint(iface string, peerKey string, newEndpoint string) error log.Debugf("parsed peer endpoint [%s]", peerAddr.String()) peerKeyParsed, err := wgtypes.ParseKey(peerKey) + if err != nil { + return err + } peers := make([]wgtypes.PeerConfig, 0) peer := wgtypes.PeerConfig{ PublicKey: peerKeyParsed, @@ -258,10 +264,12 @@ type wgLink struct { attrs *netlink.LinkAttrs } +// Attrs returns the Wireguard's default attributes func (w *wgLink) Attrs() *netlink.LinkAttrs { return w.attrs } +// Type returns the interface type func (w *wgLink) Type() string { return "wireguard" } diff --git a/iface/iface_darwin.go b/iface/iface_darwin.go index 0481fa58574..8483651c758 100644 --- a/iface/iface_darwin.go +++ b/iface/iface_darwin.go @@ -7,9 +7,9 @@ import ( "strings" ) -const ( - interfacePrefix = "utun" -) +//const ( +// interfacePrefix = "utun" +//) // assignAddr Adds IP address to the tunnel interface and network route based on the range provided func assignAddr(iface string, address string) error { diff --git a/iface/iface_linux.go b/iface/iface_linux.go index d43e4c65244..f350876662d 100644 --- a/iface/iface_linux.go +++ b/iface/iface_linux.go @@ -6,9 +6,9 @@ import ( "os" ) -const ( - interfacePrefix = "wg" -) +//const ( +// interfacePrefix = "wg" +//) // assignAddr Adds IP address to the tunnel interface func assignAddr(iface string, address string) error { From e6358e7bb27e723b0d6a8e0d58057ae73a80fca1 Mon Sep 17 00:00:00 2001 From: mlsmaycon Date: Sat, 15 May 2021 15:20:49 +0500 Subject: [PATCH 2/9] fix doc and lint warns for signal package --- cmd/up.go | 7 +++++-- signal/client.go | 23 +++++++++++++++-------- signal/encryption.go | 4 ++-- signal/fingerprint.go | 3 ++- signal/peer/peer.go | 10 ++++++---- signal/signal.go | 9 ++++----- 6 files changed, 34 insertions(+), 22 deletions(-) diff --git a/cmd/up.go b/cmd/up.go index df8466ac820..bf48bde8a5a 100644 --- a/cmd/up.go +++ b/cmd/up.go @@ -30,7 +30,7 @@ var ( } ctx := context.Background() - signalClient, err := sig.NewClient(config.SignalAddr, myKey, ctx) + signalClient, err := sig.NewClient(ctx, config.SignalAddr, myKey) if err != nil { log.Errorf("error while connecting to the Signal Exchange Service %s: %s", config.SignalAddr, err) os.Exit(ExitSetupFailed) @@ -41,7 +41,10 @@ var ( engine := connection.NewEngine(signalClient, config.StunTurnURLs, config.WgIface, config.WgAddr) err = engine.Start(myKey, config.Peers) - + if err != nil { + log.Errorf("error while starting the engine: %s", err) + os.Exit(ExitSetupFailed) + } //signalClient.WaitConnected() SetupCloseHandler() diff --git a/signal/client.go b/signal/client.go index 353806858d1..28773dcf8a3 100644 --- a/signal/client.go +++ b/signal/client.go @@ -21,7 +21,7 @@ import ( // A set of tools to exchange connection details (Wireguard endpoints) with the remote peer. -// Wraps the Signal Exchange Service gRpc client +// Client Wraps the Signal Exchange Service gRpc client type Client struct { key wgtypes.Key encryptionKey string @@ -33,12 +33,13 @@ type Client struct { connWg sync.WaitGroup //todo use a channel instead?? } -// Closes underlying connections to the Signal Exchange +// Close Closes underlying connections to the Signal Exchange func (c *Client) Close() error { return c.signalConn.Close() } -func NewClient(addr string, key wgtypes.Key, ctx context.Context) (*Client, error) { +// NewClient creates a new Signal client +func NewClient(ctx context.Context, addr string, key wgtypes.Key) (*Client, error) { conn, err := grpc.DialContext( ctx, @@ -63,7 +64,7 @@ func NewClient(addr string, key wgtypes.Key, ctx context.Context) (*Client, erro }, nil } -// Connects to the Signal Exchange message stream and starts receiving messages. +// Receive Connects to the Signal Exchange message stream and starts receiving messages. // The messages will be handled by msgHandler function provided. // This function runs a goroutine underneath and reconnects to the Signal Exchange if errors occur (e.g. Exchange restart) // The key is the identifier of our Peer (could be Wireguard public key) @@ -124,12 +125,12 @@ func (c *Client) connect(key string, msgHandler func(msg *proto.Message) error) return c.receive(stream, msgHandler) } -// Waits until the client is connected to the message stream +// WaitConnected waits until the client is connected to the message stream func (c *Client) WaitConnected() { c.connWg.Wait() } -// Sends a message to the remote Peer through the Signal Exchange using established stream connection to the Signal Server +// SendToStream sends a message to the remote Peer through the Signal Exchange using established stream connection to the Signal Server // The Client.Receive method must be called before sending messages to establish initial connection to the Signal Exchange // Client.connWg can be used to wait func (c *Client) SendToStream(msg *proto.EncryptedMessage) error { @@ -154,6 +155,9 @@ func (c *Client) decryptMessage(msg *proto.EncryptedMessage) (*proto.Message, er return nil, err } decryptedBody, err := Decrypt(msg.GetBody(), remoteKey, c.key) + if err != nil { + return nil, err + } body := &proto.Body{} err = pb.Unmarshal(decryptedBody, body) if err != nil { @@ -190,7 +194,7 @@ func (c *Client) encryptMessage(msg *proto.Message) (*proto.EncryptedMessage, er }, nil } -// Sends a message to the remote Peer through the Signal Exchange. +// Send sends a message to the remote Peer through the Signal Exchange. func (c *Client) Send(msg *proto.Message) error { encryptedMessage, err := c.encryptMessage(msg) @@ -206,7 +210,7 @@ func (c *Client) Send(msg *proto.Message) error { return nil } -// Receives messages from other peers coming through the Signal Exchange +// receive receives messages from other peers coming through the Signal Exchange func (c *Client) receive(stream proto.SignalExchange_ConnectStreamClient, msgHandler func(msg *proto.Message) error) error { @@ -240,6 +244,7 @@ func (c *Client) receive(stream proto.SignalExchange_ConnectStreamClient, } } +// UnMarshalCredential parses the credentials from the message and returns a Credential instance func UnMarshalCredential(msg *proto.Message) (*Credential, error) { credential := strings.Split(msg.GetBody().GetPayload(), ":") @@ -252,6 +257,7 @@ func UnMarshalCredential(msg *proto.Message) (*Credential, error) { }, nil } +// MarshalCredential marsharl a Credential instance and returns a Message object func MarshalCredential(myKey wgtypes.Key, remoteKey wgtypes.Key, credential *Credential, t proto.Body_Type) (*proto.Message, error) { return &proto.Message{ Key: myKey.PublicKey().String(), @@ -263,6 +269,7 @@ func MarshalCredential(myKey wgtypes.Key, remoteKey wgtypes.Key, credential *Cre }, nil } +// Credential is an instance of a Client's Credential type Credential struct { UFrag string Pwd string diff --git a/signal/encryption.go b/signal/encryption.go index 2e10d66de2a..2f4f1bccb30 100644 --- a/signal/encryption.go +++ b/signal/encryption.go @@ -13,7 +13,7 @@ import ( // These tools use Golang crypto package (Curve25519, XSalsa20 and Poly1305 to encrypt and authenticate) // Wireguard keys are used for encryption -// Encrypts a message using local Wireguard private key and remote peer's public key. +// Encrypt encrypts a message using local Wireguard private key and remote peer's public key. func Encrypt(msg []byte, peersPublicKey wgtypes.Key, privateKey wgtypes.Key) ([]byte, error) { nonce, err := genNonce() if err != nil { @@ -22,7 +22,7 @@ func Encrypt(msg []byte, peersPublicKey wgtypes.Key, privateKey wgtypes.Key) ([] return box.Seal(nonce[:], msg, nonce, toByte32(peersPublicKey), toByte32(privateKey)), nil } -// Decrypts a message that has been encrypted by the remote peer using Wireguard private key and remote peer's public key. +// Decrypt decrypts a message that has been encrypted by the remote peer using Wireguard private key and remote peer's public key. func Decrypt(encryptedMsg []byte, peersPublicKey wgtypes.Key, privateKey wgtypes.Key) ([]byte, error) { nonce, err := genNonce() if err != nil { diff --git a/signal/fingerprint.go b/signal/fingerprint.go index 7e350d5b1df..1a88e19ec39 100644 --- a/signal/fingerprint.go +++ b/signal/fingerprint.go @@ -6,10 +6,11 @@ import ( ) const ( + // HexTable Table of Hexadecimal chars HexTable = "0123456789abcdef" ) -// Generates a SHA256 Fingerprint of the string +// FingerPrint generates a SHA256 Fingerprint of the string func FingerPrint(key string) string { hasher := sha256.New() hasher.Write([]byte(key)) diff --git a/signal/peer/peer.go b/signal/peer/peer.go index 5f08a5ebe59..355cdc0891d 100644 --- a/signal/peer/peer.go +++ b/signal/peer/peer.go @@ -5,7 +5,7 @@ import ( "github.com/wiretrustee/wiretrustee/signal/proto" ) -// Representation of a connected Peer +// Peer representation of a connected Peer type Peer struct { // a unique id of the Peer (e.g. sha256 fingerprint of the Wireguard public key) Id string @@ -14,6 +14,7 @@ type Peer struct { Stream proto.SignalExchange_ConnectStreamServer } +// NewPeer creates a new instance of a connected Peer func NewPeer(id string, stream proto.SignalExchange_ConnectStreamServer) *Peer { return &Peer{ Id: id, @@ -21,19 +22,20 @@ func NewPeer(id string, stream proto.SignalExchange_ConnectStreamServer) *Peer { } } -// registry that holds all currently connected Peers +// Registry registry that holds all currently connected Peers type Registry struct { // Peer.key -> Peer Peers map[string]*Peer } +// NewRegistry creates a new connected Peer registry func NewRegistry() *Registry { return &Registry{ Peers: make(map[string]*Peer), } } -// Registers peer in the registry +// Register registers peer in the registry func (reg *Registry) Register(peer *Peer) { if _, exists := reg.Peers[peer.Id]; exists { log.Warnf("peer [%s] has been already registered", peer.Id) @@ -45,7 +47,7 @@ func (reg *Registry) Register(peer *Peer) { reg.Peers[peer.Id] = peer } -// Deregister Peer from the Registry (usually once it disconnects) +// DeregisterHub deregister Peer from the Registry (usually once it disconnects) func (reg *Registry) DeregisterHub(peer *Peer) { if _, ok := reg.Peers[peer.Id]; ok { delete(reg.Peers, peer.Id) diff --git a/signal/signal.go b/signal/signal.go index 91b5bd5f3a9..efd381f443d 100644 --- a/signal/signal.go +++ b/signal/signal.go @@ -2,7 +2,6 @@ package signal import ( "context" - "flag" "fmt" log "github.com/sirupsen/logrus" "github.com/wiretrustee/wiretrustee/signal/peer" @@ -13,20 +12,19 @@ import ( "io" ) -var ( - port = flag.Int("port", 10000, "The server port") -) - +// SignalExchangeServer an instance of a Signal server type SignalExchangeServer struct { registry *peer.Registry } +// NewServer creates a new Signal server func NewServer() *SignalExchangeServer { return &SignalExchangeServer{ registry: peer.NewRegistry(), } } +// Send forwards a message to the signal peer func (s *SignalExchangeServer) Send(ctx context.Context, msg *proto.EncryptedMessage) (*proto.EncryptedMessage, error) { if _, found := s.registry.Peers[msg.Key]; !found { @@ -47,6 +45,7 @@ func (s *SignalExchangeServer) Send(ctx context.Context, msg *proto.EncryptedMes return &proto.EncryptedMessage{}, nil } +// ConnectStream connects to the exchange stream func (s *SignalExchangeServer) ConnectStream(stream proto.SignalExchange_ConnectStreamServer) error { p, err := s.connectPeer(stream) if err != nil { From f1cff0e13a643f7f5bf6c5bc9842d3a23df71432 Mon Sep 17 00:00:00 2001 From: mlsmaycon Date: Sat, 15 May 2021 15:23:56 +0500 Subject: [PATCH 3/9] fix doc and lint warns for connection package --- connection/connection.go | 15 ++++++++++++--- connection/engine.go | 17 ++++++++++++----- connection/wgproxy.go | 8 ++++++-- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/connection/connection.go b/connection/connection.go index 13fdf932df8..129653c404e 100644 --- a/connection/connection.go +++ b/connection/connection.go @@ -11,14 +11,16 @@ import ( ) var ( + // DefaultWgKeepAlive default Wireguard keep alive constant DefaultWgKeepAlive = 20 * time.Second ) +// ConnConfig Connection configuration struct type ConnConfig struct { // Local Wireguard listening address e.g. 127.0.0.1:51820 WgListenAddr string // A Local Wireguard Peer IP address in CIDR notation e.g. 10.30.30.1/24 - WgPeerIp string + WgPeerIP string // Local Wireguard Interface name (e.g. wg0) WgIface string // Wireguard allowed IPs (e.g. 10.30.30.2/32) @@ -31,11 +33,13 @@ type ConnConfig struct { StunTurnURLS []*ice.URL } +// IceCredentials ICE protocol credentials struct type IceCredentials struct { uFrag string pwd string } +// Connection Holds information about a connection and handles signal protocol type Connection struct { Config ConnConfig // signalCandidate is a handler function to signal remote peer about local connection candidate @@ -61,6 +65,7 @@ type Connection struct { remoteAuthCond sync.Once } +// NewConnection Creates a new connection and sets handling functions for signal protocol func NewConnection(config ConnConfig, signalCandidate func(candidate ice.Candidate) error, signalOffer func(uFrag string, pwd string) error, @@ -151,6 +156,7 @@ func (conn *Connection) Open(timeout time.Duration) error { } } +// Close Closes a peer connection func (conn *Connection) Close() error { var err error conn.closeCond.Do(func() { @@ -176,6 +182,7 @@ func (conn *Connection) Close() error { return err } +// OnAnswer Handles the answer from the other peer func (conn *Connection) OnAnswer(remoteAuth IceCredentials) error { conn.remoteAuthCond.Do(func() { @@ -185,23 +192,25 @@ func (conn *Connection) OnAnswer(remoteAuth IceCredentials) error { return nil } +// OnOffer Handles the offer from the other peer func (conn *Connection) OnOffer(remoteAuth IceCredentials) error { conn.remoteAuthCond.Do(func() { log.Debugf("OnOffer from peer %s", conn.Config.RemoteWgKey.String()) conn.remoteAuthChannel <- remoteAuth uFrag, pwd, err := conn.agent.GetLocalUserCredentials() - if err != nil { + if err != nil { //nolint } err = conn.signalAnswer(uFrag, pwd) - if err != nil { + if err != nil { //nolint } }) return nil } +// OnRemoteCandidate Handles remote candidate provided by the peer. func (conn *Connection) OnRemoteCandidate(candidate ice.Candidate) error { log.Debugf("onRemoteCandidate from peer %s -> %s", conn.Config.RemoteWgKey.String(), candidate.String()) diff --git a/connection/engine.go b/connection/engine.go index 5399c9b21e1..e9e66f21700 100644 --- a/connection/engine.go +++ b/connection/engine.go @@ -12,6 +12,7 @@ import ( "time" ) +// Engine is an instance of the Connection Engine type Engine struct { // a list of STUN and TURN servers stunsTurns []*ice.URL @@ -22,27 +23,31 @@ type Engine struct { // Wireguard interface wgIface string // Wireguard local address - wgIp string + wgIP string } +// Peer is an instance of the Connection Peer type Peer struct { WgPubKey string WgAllowedIps string } +// NewEngine creates a new Connection Engine func NewEngine(signal *signal.Client, stunsTurns []*ice.URL, wgIface string, wgAddr string) *Engine { return &Engine{ stunsTurns: stunsTurns, signal: signal, wgIface: wgIface, - wgIp: wgAddr, + wgIP: wgAddr, conns: map[string]*Connection{}, } } +// Start creates a new tunnel interface and listens to signals from the Signal service. +// It also creates an Go routine to handle each peer communication from the config file func (e *Engine) Start(myKey wgtypes.Key, peers []Peer) error { - err := iface.Create(e.wgIface, e.wgIp) + err := iface.Create(e.wgIface, e.wgIP) if err != nil { log.Errorf("error while creating interface %s: [%s]", e.wgIface, err.Error()) return err @@ -102,7 +107,7 @@ func (e *Engine) openPeerConnection(wgPort int, myKey wgtypes.Key, peer Peer) (* remoteKey, _ := wgtypes.ParseKey(peer.WgPubKey) connConfig := &ConnConfig{ WgListenAddr: fmt.Sprintf("127.0.0.1:%d", wgPort), - WgPeerIp: e.wgIp, + WgPeerIP: e.wgIP, WgIface: e.wgIface, WgAllowedIPs: peer.WgAllowedIps, WgKey: myKey, @@ -161,7 +166,9 @@ func signalAuth(uFrag string, pwd string, myKey wgtypes.Key, remoteKey wgtypes.K msg, err := signal.MarshalCredential(myKey, remoteKey, &signal.Credential{ UFrag: uFrag, Pwd: pwd}, t) - + if err != nil { + return err + } err = s.Send(msg) if err != nil { return err diff --git a/connection/wgproxy.go b/connection/wgproxy.go index f29d13eea1e..ef65de6835c 100644 --- a/connection/wgproxy.go +++ b/connection/wgproxy.go @@ -7,6 +7,7 @@ import ( "net" ) +// WgProxy an instance of an instance of the Connection Wireguard Proxy type WgProxy struct { iface string remoteKey string @@ -16,6 +17,7 @@ type WgProxy struct { wgConn net.Conn } +// NewWgProxy creates a new Connection Wireguard Proxy func NewWgProxy(iface string, remoteKey string, allowedIps string, wgAddr string) *WgProxy { return &WgProxy{ iface: iface, @@ -26,6 +28,7 @@ func NewWgProxy(iface string, remoteKey string, allowedIps string, wgAddr string } } +// Close closes the proxy func (p *WgProxy) Close() error { close(p.close) @@ -39,6 +42,7 @@ func (p *WgProxy) Close() error { return nil } +// Start starts a new proxy using the ICE connection func (p *WgProxy) Start(remoteConn *ice.Conn) error { wgConn, err := net.Dial("udp", p.wgAddr) @@ -78,7 +82,7 @@ func (p *WgProxy) proxyToRemotePeer(remoteConn *ice.Conn) { continue } - n, err = remoteConn.Write(buf[:n]) + _, err = remoteConn.Write(buf[:n]) if err != nil { //log.Warnln("failed writing to remote peer: ", err.Error()) } @@ -102,7 +106,7 @@ func (p *WgProxy) proxyToLocalWireguard(remoteConn *ice.Conn) { //log.Errorf("failed reading from remote connection %s", err) } - n, err = p.wgConn.Write(buf[:n]) + _, err = p.wgConn.Write(buf[:n]) if err != nil { //log.Errorf("failed writing to local Wireguard instance %s", err) } From 6d339295be8f71b63708ba319078e5bda8cf05d0 Mon Sep 17 00:00:00 2001 From: mlsmaycon Date: Sat, 15 May 2021 15:24:30 +0500 Subject: [PATCH 4/9] fix doc --- util/retry.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/retry.go b/util/retry.go index b04854b245c..3bffcf288d8 100644 --- a/util/retry.go +++ b/util/retry.go @@ -5,7 +5,7 @@ import ( "time" ) -// Retries a given toExec function calling onError on failed attempts +// Retry retries a given toExec function calling onError on failed attempts // onError shouldn be a lightweight function and shouldn't be blocking func Retry(attempts int, sleep time.Duration, toExec func() error, onError func(e error)) error { if err := toExec(); err != nil { From 73720951d72c74c13901643caafaec4f2dfbd2f7 Mon Sep 17 00:00:00 2001 From: mlsmaycon Date: Sat, 15 May 2021 15:33:07 +0500 Subject: [PATCH 5/9] fix doc and lint warns for the cmd package --- cmd/addpeer.go | 4 ++-- cmd/config.go | 1 + cmd/init.go | 8 ++++---- cmd/root.go | 5 ++++- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/cmd/addpeer.go b/cmd/addpeer.go index 0caaaeb0710..c03af70212e 100644 --- a/cmd/addpeer.go +++ b/cmd/addpeer.go @@ -40,6 +40,6 @@ var ( func init() { addPeerCmd.PersistentFlags().StringVar(&key, "key", "", "Wireguard public key of the remote peer") addPeerCmd.PersistentFlags().StringVar(&allowedIPs, "allowedIPs", "", "Wireguard Allowed IPs for the remote peer, e.g 10.30.30.2/32") - addPeerCmd.MarkPersistentFlagRequired("key") - addPeerCmd.MarkPersistentFlagRequired("allowedIPs") + addPeerCmd.MarkPersistentFlagRequired("key") //nolint + addPeerCmd.MarkPersistentFlagRequired("allowedIPs") //nolint } diff --git a/cmd/config.go b/cmd/config.go index ad7640afef8..b11ef24f6d0 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -8,6 +8,7 @@ import ( "os" ) +// Config Configuration type type Config struct { // Wireguard private key of local peer PrivateKey string diff --git a/cmd/init.go b/cmd/init.go index a66cf9a89c7..9569a26b7ba 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -109,10 +109,10 @@ func init() { //todo user:password@protocol:host:port not the best way to pass TURN credentials, do it according to https://tools.ietf.org/html/rfc7065 E.g. use oauth initCmd.PersistentFlags().StringVar(&turnURLs, "turnURLs", "", "Comma separated TURN server URLs: user:password@protocol:host:port, e.g. user:password@turn:stun.wiretrustee.com:3468") //initCmd.MarkPersistentFlagRequired("configPath") - initCmd.MarkPersistentFlagRequired("wgLocalAddr") - initCmd.MarkPersistentFlagRequired("signalAddr") - initCmd.MarkPersistentFlagRequired("stunURLs") - initCmd.MarkPersistentFlagRequired("turnURLs") + initCmd.MarkPersistentFlagRequired("wgLocalAddr") //nolint + initCmd.MarkPersistentFlagRequired("signalAddr") //nolint + initCmd.MarkPersistentFlagRequired("stunURLs") //nolint + initCmd.MarkPersistentFlagRequired("turnURLs") //nolint } // generateKey generates a new Wireguard private key diff --git a/cmd/root.go b/cmd/root.go index 014bd42e03b..955b08a7a76 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -10,6 +10,7 @@ import ( ) const ( + // ExitSetupFailed defines exit code ExitSetupFailed = 1 ) @@ -38,6 +39,7 @@ func init() { rootCmd.AddCommand(signalCmd) } +// SetupCloseHandler handles SIGTERM signal and exits with success func SetupCloseHandler() { c := make(chan os.Signal) signal.Notify(c, os.Interrupt, syscall.SIGTERM) @@ -46,10 +48,11 @@ func SetupCloseHandler() { os.Exit(0) } +// InitLog parses and sets log-level input func InitLog(logLevel string) { level, err := log.ParseLevel(logLevel) if err != nil { - log.Errorf("efailed parsing log-level %s: %s", logLevel, err) + log.Errorf("Failed parsing log-level %s: %s", logLevel, err) os.Exit(ExitSetupFailed) } log.SetLevel(level) From 84c6eb5e167c0c6053005c8324dcc8a8f6283777 Mon Sep 17 00:00:00 2001 From: mlsmaycon Date: Sat, 15 May 2021 15:44:35 +0500 Subject: [PATCH 6/9] Add golangci-lint workflow --- .github/workflows/golangci-lint.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 .github/workflows/golangci-lint.yml diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml new file mode 100644 index 00000000000..956fcd1700b --- /dev/null +++ b/.github/workflows/golangci-lint.yml @@ -0,0 +1,14 @@ +name: golangci-lint +on: + push: + branches: + - main + pull_request: +jobs: + golangci: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: golangci-lint + uses: golangci/golangci-lint-action@v2 \ No newline at end of file From 5342f10e7fc9b287deb1722c9d6fe304d2c2c212 Mon Sep 17 00:00:00 2001 From: braginini Date: Wed, 19 May 2021 10:58:21 +0200 Subject: [PATCH 7/9] fix: golint errors --- cmd/up.go | 4 ---- connection/connection.go | 6 ++---- go.mod | 2 ++ go.sum | 14 ++++++++++++++ signal/client.go | 11 +++++------ 5 files changed, 23 insertions(+), 14 deletions(-) diff --git a/cmd/up.go b/cmd/up.go index da0490c040a..f5e514c702b 100644 --- a/cmd/up.go +++ b/cmd/up.go @@ -10,10 +10,6 @@ import ( "os" ) -func toByte32(key wgtypes.Key) *[32]byte { - return (*[32]byte)(&key) -} - var ( upCmd = &cobra.Command{ Use: "up", diff --git a/connection/connection.go b/connection/connection.go index 665e3eea257..0c3eb1adaa0 100644 --- a/connection/connection.go +++ b/connection/connection.go @@ -159,10 +159,8 @@ func (conn *Connection) Open(timeout time.Duration) error { } // wait until connection has been closed - select { - case <-conn.closeCond.C: - return fmt.Errorf("connection to peer %s has been closed", conn.Config.RemoteWgKey.String()) - } + <-conn.closeCond.C + return fmt.Errorf("connection to peer %s has been closed", conn.Config.RemoteWgKey.String()) } // Close Closes a peer connection diff --git a/go.mod b/go.mod index 5d32d078dc3..1c6593327c0 100644 --- a/go.mod +++ b/go.mod @@ -12,6 +12,8 @@ require ( github.com/vishvananda/netlink v1.1.0 github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 + golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect + golang.org/x/tools v0.1.1 // indirect golang.zx2c4.com/wireguard v0.0.20201118 golang.zx2c4.com/wireguard/wgctrl v0.0.0-20200609130330-bd2cb7843e1b google.golang.org/grpc v1.32.0 diff --git a/go.sum b/go.sum index 6575f99352b..b26335e4a61 100644 --- a/go.sum +++ b/go.sum @@ -230,6 +230,7 @@ github.com/vishvananda/netns v0.0.0-20180720170159-13995c7128cc/go.mod h1:ZjcWmF github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df h1:OviZH7qLw/7ZovXvuNyL3XQl8UFofeikI1NW1Gypu7k= github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df/go.mod h1:JP3t17pCcGlemwknint6hfoeCVQrEMVwxRLRjXpq+BU= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= +github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= @@ -242,6 +243,7 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191002192127-34f69633bfdc/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200204104054-c9f3fb736b72/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20201117144127-c1f2f97bffc9/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= @@ -261,10 +263,14 @@ golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHl golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 h1:VLliZ0d+/avPrXXH+OakdXhpJuEoBZuwh1m2j7U6Iug= +golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= +golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= +golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -291,6 +297,7 @@ golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210331212208-0fccb6fa2b5c h1:KHUzaHIpjWVlVVNh65G3hhuj3KB1HnjY6Cq5cTvRQT8= golang.org/x/net v0.0.0-20210331212208-0fccb6fa2b5c/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= +golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -299,6 +306,7 @@ golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -326,6 +334,7 @@ golang.org/x/sys v0.0.0-20201117222635-ba5294a509c7/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44 h1:Bli41pIlzTzf3KEY06n+xnzK/BESIg2ze4Pgfh/aI8c= golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -353,7 +362,12 @@ golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.1.1 h1:wGiQel/hW0NnEkJUk8lbzkX2gFJU6PFxf1v5OlCfuOs= +golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/signal/client.go b/signal/client.go index 28773dcf8a3..244a269c060 100644 --- a/signal/client.go +++ b/signal/client.go @@ -23,12 +23,11 @@ import ( // Client Wraps the Signal Exchange Service gRpc client type Client struct { - key wgtypes.Key - encryptionKey string - realClient proto.SignalExchangeClient - signalConn *grpc.ClientConn - ctx context.Context - stream proto.SignalExchange_ConnectStreamClient + key wgtypes.Key + realClient proto.SignalExchangeClient + signalConn *grpc.ClientConn + ctx context.Context + stream proto.SignalExchange_ConnectStreamClient //waiting group to notify once stream is connected connWg sync.WaitGroup //todo use a channel instead?? } From 790858c31b576967d7ba91d9b534356ef9dc0cfa Mon Sep 17 00:00:00 2001 From: braginini Date: Wed, 19 May 2021 11:13:25 +0200 Subject: [PATCH 8/9] fix: golint errors (part 2) --- cmd/config.go | 2 +- cmd/init.go | 2 +- cmd/root.go | 14 ++++++++------ cmd/signal.go | 1 + cmd/up.go | 1 + connection/connection.go | 2 +- connection/engine.go | 26 +++++++++++++------------- connection/wgproxy.go | 5 ++++- go.sum | 13 ++----------- 9 files changed, 32 insertions(+), 34 deletions(-) diff --git a/cmd/config.go b/cmd/config.go index 3961d4619a4..4bbef1c8d7c 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -2,7 +2,7 @@ package cmd import ( "encoding/json" - "github.com/pion/ice/v2" + ice "github.com/pion/ice/v2" "github.com/wiretrustee/wiretrustee/connection" "io/ioutil" "os" diff --git a/cmd/init.go b/cmd/init.go index 9569a26b7ba..5c25262dc38 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -1,7 +1,7 @@ package cmd import ( - "github.com/pion/ice/v2" + ice "github.com/pion/ice/v2" log "github.com/sirupsen/logrus" "github.com/spf13/cobra" "golang.zx2c4.com/wireguard/wgctrl/wgtypes" diff --git a/cmd/root.go b/cmd/root.go index 955b08a7a76..c499a34e33f 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -6,7 +6,6 @@ import ( "github.com/spf13/cobra" "os" "os/signal" - "syscall" ) const ( @@ -41,11 +40,14 @@ func init() { // SetupCloseHandler handles SIGTERM signal and exits with success func SetupCloseHandler() { - c := make(chan os.Signal) - signal.Notify(c, os.Interrupt, syscall.SIGTERM) - <-c - fmt.Println("\r- Ctrl+C pressed in Terminal") - os.Exit(0) + c := make(chan os.Signal, 1) + signal.Notify(c, os.Interrupt) + go func() { + for range c { + fmt.Println("\r- Ctrl+C pressed in Terminal") + os.Exit(0) + } + }() } // InitLog parses and sets log-level input diff --git a/cmd/signal.go b/cmd/signal.go index c19a3011bb1..7c8ee4752ce 100644 --- a/cmd/signal.go +++ b/cmd/signal.go @@ -37,6 +37,7 @@ var ( } SetupCloseHandler() + select {} }, } ) diff --git a/cmd/up.go b/cmd/up.go index f5e514c702b..bb94dbff7f5 100644 --- a/cmd/up.go +++ b/cmd/up.go @@ -48,6 +48,7 @@ var ( //signalClient.WaitConnected() SetupCloseHandler() + select {} }, } ) diff --git a/connection/connection.go b/connection/connection.go index 0c3eb1adaa0..67387571cfd 100644 --- a/connection/connection.go +++ b/connection/connection.go @@ -3,7 +3,7 @@ package connection import ( "context" "fmt" - "github.com/pion/ice/v2" + ice "github.com/pion/ice/v2" log "github.com/sirupsen/logrus" "golang.zx2c4.com/wireguard/wgctrl/wgtypes" "sync" diff --git a/connection/engine.go b/connection/engine.go index fc1b95581a4..80928e0a35f 100644 --- a/connection/engine.go +++ b/connection/engine.go @@ -3,7 +3,7 @@ package connection import ( "fmt" "github.com/cenkalti/backoff/v4" - "github.com/pion/ice/v2" + ice "github.com/pion/ice/v2" log "github.com/sirupsen/logrus" "github.com/wiretrustee/wiretrustee/iface" "github.com/wiretrustee/wiretrustee/signal" @@ -38,11 +38,11 @@ type Peer struct { 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{}, + stunsTurns: stunsTurns, + signal: signal, + wgIface: wgIface, + wgIP: wgAddr, + conns: map[string]*Connection{}, iFaceBlackList: iFaceBlackList, } } @@ -110,13 +110,13 @@ func (e *Engine) openPeerConnection(wgPort int, myKey wgtypes.Key, peer Peer) (* remoteKey, _ := wgtypes.ParseKey(peer.WgPubKey) connConfig := &ConnConfig{ - WgListenAddr: fmt.Sprintf("127.0.0.1:%d", wgPort), - WgPeerIP: e.wgIP, - WgIface: e.wgIface, - WgAllowedIPs: peer.WgAllowedIps, - WgKey: myKey, - RemoteWgKey: remoteKey, - StunTurnURLS: e.stunsTurns, + WgListenAddr: fmt.Sprintf("127.0.0.1:%d", wgPort), + WgPeerIP: e.wgIP, + WgIface: e.wgIface, + WgAllowedIPs: peer.WgAllowedIps, + WgKey: myKey, + RemoteWgKey: remoteKey, + StunTurnURLS: e.stunsTurns, iFaceBlackList: e.iFaceBlackList, } diff --git a/connection/wgproxy.go b/connection/wgproxy.go index ef65de6835c..8eae1d111b4 100644 --- a/connection/wgproxy.go +++ b/connection/wgproxy.go @@ -1,7 +1,7 @@ package connection import ( - "github.com/pion/ice/v2" + ice "github.com/pion/ice/v2" log "github.com/sirupsen/logrus" "github.com/wiretrustee/wiretrustee/iface" "net" @@ -85,6 +85,7 @@ func (p *WgProxy) proxyToRemotePeer(remoteConn *ice.Conn) { _, err = remoteConn.Write(buf[:n]) if err != nil { //log.Warnln("failed writing to remote peer: ", err.Error()) + continue } } } @@ -104,11 +105,13 @@ func (p *WgProxy) proxyToLocalWireguard(remoteConn *ice.Conn) { n, err := remoteConn.Read(buf) if err != nil { //log.Errorf("failed reading from remote connection %s", err) + continue } _, err = p.wgConn.Write(buf[:n]) if err != nil { //log.Errorf("failed writing to local Wireguard instance %s", err) + continue } } } diff --git a/go.sum b/go.sum index b26335e4a61..4f3812c34e4 100644 --- a/go.sum +++ b/go.sum @@ -36,7 +36,6 @@ github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7 github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= @@ -74,7 +73,6 @@ github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/nftables v0.0.0-20201230142148-715e31cb3c31 h1:kyEB9geFhgDyawmvavtNu9iGW9ri/iq54XTSNIEeHxI= @@ -115,7 +113,6 @@ github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NH github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= github.com/jsimonetti/rtnetlink v0.0.0-20190606172950-9527aa82566a/go.mod h1:Oz+70psSo5OFh8DBl0Zv2ACw7Esh6pPUphlvZG9x7uw= -github.com/jsimonetti/rtnetlink v0.0.0-20200117123717-f846d4f6c1f4 h1:nwOc1YaOrYJ37sEBrtWZrdqzK22hiJs3GpDmP3sR2Yw= github.com/jsimonetti/rtnetlink v0.0.0-20200117123717-f846d4f6c1f4/go.mod h1:WGuG/smIU4J/54PblvSbh+xvCZmpJnFgr3ds6Z55XMQ= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= @@ -142,7 +139,6 @@ github.com/mdlayher/netlink v1.0.0/go.mod h1:KxeJAFOFLG6AjpyDkQ/iIhxygIUKD+vcwqc github.com/mdlayher/netlink v1.1.0 h1:mpdLgm+brq10nI9zM1BpX1kpDbh3NLl3RSnVq6ZSkfg= github.com/mdlayher/netlink v1.1.0/go.mod h1:H4WCitaheIsdF9yOYu8CFmCgQthAPIWZmcKp9uZHgmY= github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= -github.com/mikioh/ipaddr v0.0.0-20190404000644-d465c8ab6721 h1:RlZweED6sbSArvlE924+mUcZuXKLBHA35U7LN621Bws= github.com/mikioh/ipaddr v0.0.0-20190404000644-d465c8ab6721/go.mod h1:Ickgr2WtCLZ2MDGd4Gr0geeCH5HybhRJbonOgQpvSxc= github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= @@ -180,7 +176,6 @@ github.com/pion/udp v0.1.1 h1:8UAPvyqmsxK8oOjloDk4wUt63TzFe9WEJkg5lChlj7o= github.com/pion/udp v0.1.1/go.mod h1:6AFo+CMdKQm7UiA0eUPA8/eVCTx8jBIITLZHc9DWX5M= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= @@ -220,7 +215,6 @@ github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= @@ -263,7 +257,6 @@ golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHl golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 h1:VLliZ0d+/avPrXXH+OakdXhpJuEoBZuwh1m2j7U6Iug= golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= @@ -295,8 +288,8 @@ golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwY golang.org/x/net v0.0.0-20201201195509-5d6afe98e0b7/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20210331212208-0fccb6fa2b5c h1:KHUzaHIpjWVlVVNh65G3hhuj3KB1HnjY6Cq5cTvRQT8= golang.org/x/net v0.0.0-20210331212208-0fccb6fa2b5c/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= +golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4 h1:4nGaVu0QrbjT/AK2PRLuQfQuh6DJve+pELhqTdAj3x0= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -332,8 +325,8 @@ golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201117222635-ba5294a509c7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44 h1:Bli41pIlzTzf3KEY06n+xnzK/BESIg2ze4Pgfh/aI8c= golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210510120138-977fb7262007 h1:gG67DSER+11cZvqIMb8S8bt0vZtiN6xWYARwirrOSfE= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= @@ -364,7 +357,6 @@ golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.1.1 h1:wGiQel/hW0NnEkJUk8lbzkX2gFJU6PFxf1v5OlCfuOs= golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -420,7 +412,6 @@ gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bl gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= From 44d5e7f2055b17f69d101470e55d32960f7ee13e Mon Sep 17 00:00:00 2001 From: braginini Date: Wed, 19 May 2021 11:17:15 +0200 Subject: [PATCH 9/9] fix: golint errors (part 3) --- signal/client.go | 2 +- signal/proto/signalexchange.pb.go | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/signal/client.go b/signal/client.go index 244a269c060..43f82b5c3f9 100644 --- a/signal/client.go +++ b/signal/client.go @@ -4,7 +4,7 @@ import ( "context" "fmt" "github.com/cenkalti/backoff/v4" - pb "github.com/golang/protobuf/proto" + pb "github.com/golang/protobuf/proto" //nolint log "github.com/sirupsen/logrus" "github.com/wiretrustee/wiretrustee/signal/proto" "golang.zx2c4.com/wireguard/wgctrl/wgtypes" diff --git a/signal/proto/signalexchange.pb.go b/signal/proto/signalexchange.pb.go index 2478a8d7396..4c1ed6f6912 100644 --- a/signal/proto/signalexchange.pb.go +++ b/signal/proto/signalexchange.pb.go @@ -6,7 +6,7 @@ package proto import ( context "context" fmt "fmt" - proto "github.com/golang/protobuf/proto" + proto "github.com/golang/protobuf/proto" //nolint _ "github.com/golang/protobuf/protoc-gen-go/descriptor" grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" @@ -57,11 +57,11 @@ func (Body_Type) EnumDescriptor() ([]byte, []int) { // Used for sending through signal. // The body of this message is the Body message encrypted with the Wireguard private key and the remote Peer key type EncryptedMessage struct { - // a sha256 fingerprint of the Wireguard public key + // Wireguard public key Key string `protobuf:"bytes,2,opt,name=key,proto3" json:"key,omitempty"` - // a sha256 fingerprint of the Wireguard public key of the remote peer to connect to + // Wireguard public key of the remote peer to connect to RemoteKey string `protobuf:"bytes,3,opt,name=remoteKey,proto3" json:"remoteKey,omitempty"` - // encrypted message body + // encrypted message Body Body []byte `protobuf:"bytes,4,opt,name=body,proto3" json:"body,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` @@ -116,9 +116,9 @@ func (m *EncryptedMessage) GetBody() []byte { // A decrypted representation of the EncryptedMessage. Used locally before/after encryption type Message struct { - // a sha256 fingerprint of the Wireguard public key + // Wireguard public key Key string `protobuf:"bytes,2,opt,name=key,proto3" json:"key,omitempty"` - // a sha256 fingerprint of the Wireguard public key of the remote peer to connect to + // Wireguard public key of the remote peer to connect to RemoteKey string `protobuf:"bytes,3,opt,name=remoteKey,proto3" json:"remoteKey,omitempty"` Body *Body `protobuf:"bytes,4,opt,name=body,proto3" json:"body,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"`