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