mirror of
https://github.com/netbirdio/netbird.git
synced 2025-01-18 20:08:28 +01:00
Fix lint issues
This commit is contained in:
parent
cfac8c4762
commit
c3e8187a47
@ -8,7 +8,6 @@ import (
|
||||
"encoding/gob"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
@ -40,7 +39,6 @@ func unmarshalToken(payload []byte) (Token, error) {
|
||||
|
||||
// TimedHMAC generates token with TTL and using pre-shared secret known to TURN server
|
||||
type TimedHMAC struct {
|
||||
mux sync.Mutex
|
||||
secret string
|
||||
timeToLive time.Duration
|
||||
}
|
||||
|
@ -23,11 +23,12 @@ func Dial(address string) (net.Conn, error) {
|
||||
HTTPClient: httpClientNbDialer(),
|
||||
}
|
||||
|
||||
wsConn, _, err := websocket.Dial(context.Background(), wsURL, opts)
|
||||
wsConn, resp, err := websocket.Dial(context.Background(), wsURL, opts)
|
||||
if err != nil {
|
||||
log.Errorf("failed to dial to Relay server '%s': %s", wsURL, err)
|
||||
return nil, err
|
||||
}
|
||||
_ = resp.Body.Close()
|
||||
|
||||
conn := NewConn(wsConn)
|
||||
return conn, nil
|
||||
|
@ -18,7 +18,7 @@ var (
|
||||
errRelayClientNotConnected = fmt.Errorf("relay client not connected")
|
||||
)
|
||||
|
||||
// RelayTrack hold the relay clients for the foregin relay servers.
|
||||
// RelayTrack hold the relay clients for the foreign relay servers.
|
||||
// With the mutex can ensure we can open new connection in case the relay connection has been established with
|
||||
// the relay server.
|
||||
type RelayTrack struct {
|
||||
|
@ -18,7 +18,9 @@ var (
|
||||
func HashID(peerID string) ([]byte, string) {
|
||||
idHash := sha256.Sum256([]byte(peerID))
|
||||
idHashString := string(prefix) + base64.StdEncoding.EncodeToString(idHash[:])
|
||||
prefixedHash := append(prefix, idHash[:]...)
|
||||
var prefixedHash []byte
|
||||
prefixedHash = append(prefixedHash, prefix...)
|
||||
prefixedHash = append(prefixedHash, idHash[:]...)
|
||||
return prefixedHash, idHashString
|
||||
}
|
||||
|
||||
|
@ -7,19 +7,19 @@ import (
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type QuicConn struct {
|
||||
type Conn struct {
|
||||
quic.Stream
|
||||
qConn quic.Connection
|
||||
}
|
||||
|
||||
func NewConn(stream quic.Stream, qConn quic.Connection) net.Conn {
|
||||
return &QuicConn{
|
||||
return &Conn{
|
||||
Stream: stream,
|
||||
qConn: qConn,
|
||||
}
|
||||
}
|
||||
|
||||
func (q QuicConn) Write(b []byte) (n int, err error) {
|
||||
func (q Conn) Write(b []byte) (n int, err error) {
|
||||
n, err = q.Stream.Write(b)
|
||||
if n != len(b) {
|
||||
log.Errorf("failed to write out the full message")
|
||||
@ -27,10 +27,10 @@ func (q QuicConn) Write(b []byte) (n int, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (q QuicConn) LocalAddr() net.Addr {
|
||||
func (q Conn) LocalAddr() net.Addr {
|
||||
return q.qConn.LocalAddr()
|
||||
}
|
||||
|
||||
func (q QuicConn) RemoteAddr() net.Addr {
|
||||
func (q Conn) RemoteAddr() net.Addr {
|
||||
return q.qConn.RemoteAddr()
|
||||
}
|
||||
|
@ -18,8 +18,7 @@ import (
|
||||
)
|
||||
|
||||
type Listener struct {
|
||||
address string
|
||||
onAcceptFn func(conn net.Conn)
|
||||
address string
|
||||
|
||||
listener *quic.Listener
|
||||
quit chan struct{}
|
||||
@ -88,7 +87,7 @@ func (l *Listener) acceptLoop(acceptFn func(conn net.Conn)) {
|
||||
|
||||
// Setup a bare-bones TLS config for the server
|
||||
func generateTLSConfig() *tls.Config {
|
||||
key, err := rsa.GenerateKey(rand.Reader, 1024)
|
||||
key, err := rsa.GenerateKey(rand.Reader, 2048)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
)
|
||||
|
||||
// Listener
|
||||
// Is it just demo code. It does not work in real life environment because the TCP is a streaming protocol, adn
|
||||
// Is it just demo code. It does not work in real life environment because the TCP is a streaming protocol, and
|
||||
// it does not handle framing.
|
||||
type Listener struct {
|
||||
address string
|
||||
|
@ -6,21 +6,21 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type UDPConn struct {
|
||||
type Conn struct {
|
||||
*net.UDPConn
|
||||
addr *net.UDPAddr
|
||||
msgChannel chan []byte
|
||||
}
|
||||
|
||||
func NewConn(conn *net.UDPConn, addr *net.UDPAddr) *UDPConn {
|
||||
return &UDPConn{
|
||||
func NewConn(conn *net.UDPConn, addr *net.UDPAddr) *Conn {
|
||||
return &Conn{
|
||||
UDPConn: conn,
|
||||
addr: addr,
|
||||
msgChannel: make(chan []byte),
|
||||
}
|
||||
}
|
||||
|
||||
func (u *UDPConn) Read(b []byte) (n int, err error) {
|
||||
func (u *Conn) Read(b []byte) (n int, err error) {
|
||||
msg, ok := <-u.msgChannel
|
||||
if !ok {
|
||||
return 0, io.EOF
|
||||
@ -30,39 +30,39 @@ func (u *UDPConn) Read(b []byte) (n int, err error) {
|
||||
return n, nil
|
||||
}
|
||||
|
||||
func (u *UDPConn) Write(b []byte) (n int, err error) {
|
||||
func (u *Conn) Write(b []byte) (n int, err error) {
|
||||
return u.UDPConn.WriteTo(b, u.addr)
|
||||
}
|
||||
|
||||
func (u *UDPConn) Close() error {
|
||||
func (u *Conn) Close() error {
|
||||
//TODO implement me
|
||||
//panic("implement me")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *UDPConn) LocalAddr() net.Addr {
|
||||
func (u *Conn) LocalAddr() net.Addr {
|
||||
return u.UDPConn.LocalAddr()
|
||||
}
|
||||
|
||||
func (u *UDPConn) RemoteAddr() net.Addr {
|
||||
func (u *Conn) RemoteAddr() net.Addr {
|
||||
return u.addr
|
||||
}
|
||||
|
||||
func (u *UDPConn) SetDeadline(t time.Time) error {
|
||||
func (u *Conn) SetDeadline(t time.Time) error {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (u *UDPConn) SetReadDeadline(t time.Time) error {
|
||||
func (u *Conn) SetReadDeadline(t time.Time) error {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (u *UDPConn) SetWriteDeadline(t time.Time) error {
|
||||
func (u *Conn) SetWriteDeadline(t time.Time) error {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (u *UDPConn) onNewMsg(b []byte) {
|
||||
func (u *Conn) onNewMsg(b []byte) {
|
||||
u.msgChannel <- b
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
|
||||
type Listener struct {
|
||||
address string
|
||||
conns map[string]*UDPConn
|
||||
conns map[string]*Conn
|
||||
onAcceptFn func(conn net.Conn)
|
||||
|
||||
listener *net.UDPConn
|
||||
@ -24,7 +24,7 @@ type Listener struct {
|
||||
func NewListener(address string) listener.Listener {
|
||||
return &Listener{
|
||||
address: address,
|
||||
conns: make(map[string]*UDPConn),
|
||||
conns: make(map[string]*Conn),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -66,7 +66,7 @@ func (r *Relay) Accept(conn net.Conn) {
|
||||
}
|
||||
|
||||
func (r *Relay) Close(ctx context.Context) {
|
||||
log.Infof("closeing connection with all peers")
|
||||
log.Infof("close connection with all peers")
|
||||
r.closeMu.Lock()
|
||||
wg := sync.WaitGroup{}
|
||||
peers := r.store.Peers()
|
||||
|
Loading…
Reference in New Issue
Block a user