mirror of
https://github.com/netbirdio/netbird.git
synced 2024-12-23 23:29:15 +01:00
Refactor: Move Signal server and client (#80)
* Move Signal Server * Move Signal Client * Cleanup duplicates and unused files * Moved Signal client tests
This commit is contained in:
parent
9f0c86c28e
commit
d5af5f1878
@ -6,8 +6,8 @@ import (
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/wiretrustee/wiretrustee/encryption"
|
||||
sig "github.com/wiretrustee/wiretrustee/signal"
|
||||
sigProto "github.com/wiretrustee/wiretrustee/signal/proto"
|
||||
"github.com/wiretrustee/wiretrustee/signal/server"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials"
|
||||
"google.golang.org/grpc/keepalive"
|
||||
@ -65,7 +65,7 @@ var (
|
||||
log.Fatalf("failed to listen: %v", err)
|
||||
}
|
||||
|
||||
sigProto.RegisterSignalExchangeServer(grpcServer, sig.NewServer())
|
||||
sigProto.RegisterSignalExchangeServer(grpcServer, server.NewServer())
|
||||
log.Printf("started server: localhost:%v", signalPort)
|
||||
if err := grpcServer.Serve(lis); err != nil {
|
||||
log.Fatalf("failed to serve: %v", err)
|
||||
|
@ -2,6 +2,7 @@ package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
signal "github.com/wiretrustee/wiretrustee/signal/client"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
@ -12,7 +13,6 @@ import (
|
||||
"github.com/wiretrustee/wiretrustee/connection"
|
||||
"github.com/wiretrustee/wiretrustee/encryption"
|
||||
mgm "github.com/wiretrustee/wiretrustee/management/proto"
|
||||
sig "github.com/wiretrustee/wiretrustee/signal"
|
||||
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/codes"
|
||||
@ -44,7 +44,7 @@ var (
|
||||
|
||||
var sigTLSEnabled = false
|
||||
ctx := context.Background()
|
||||
signalClient, err := sig.NewClient(ctx, config.SignalAddr, myKey, sigTLSEnabled)
|
||||
signalClient, err := signal.NewClient(ctx, config.SignalAddr, myKey, sigTLSEnabled)
|
||||
if err != nil {
|
||||
log.Errorf("error while connecting to the Signal Exchange Service %s: %s", config.SignalAddr, err)
|
||||
os.Exit(ExitSetupFailed)
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
ice "github.com/pion/ice/v2"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/wiretrustee/wiretrustee/iface"
|
||||
"github.com/wiretrustee/wiretrustee/signal"
|
||||
signal "github.com/wiretrustee/wiretrustee/signal/client"
|
||||
sProto "github.com/wiretrustee/wiretrustee/signal/proto"
|
||||
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
||||
"sync"
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
ice "github.com/pion/ice/v2"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/wiretrustee/wiretrustee/iface"
|
||||
sig "github.com/wiretrustee/wiretrustee/signal"
|
||||
signal "github.com/wiretrustee/wiretrustee/signal/client"
|
||||
"golang.zx2c4.com/wireguard/wgctrl"
|
||||
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
||||
"testing"
|
||||
@ -41,7 +41,7 @@ func Test_Start(t *testing.T) {
|
||||
|
||||
var sigTLSEnabled = false
|
||||
|
||||
signalClient, err := sig.NewClient(ctx, "signal.wiretrustee.com:10000", testKey, sigTLSEnabled)
|
||||
signalClient, err := signal.NewClient(ctx, "signal.wiretrustee.com:10000", testKey, sigTLSEnabled)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package signal
|
||||
package client
|
||||
|
||||
import (
|
||||
"context"
|
@ -1,4 +1,4 @@
|
||||
package signal_test
|
||||
package client
|
||||
|
||||
import (
|
||||
. "github.com/onsi/ginkgo"
|
@ -1,12 +1,12 @@
|
||||
package signal_test
|
||||
package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/wiretrustee/wiretrustee/signal"
|
||||
sigProto "github.com/wiretrustee/wiretrustee/signal/proto"
|
||||
"github.com/wiretrustee/wiretrustee/signal/server"
|
||||
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/keepalive"
|
||||
@ -143,9 +143,9 @@ var _ = Describe("Client", func() {
|
||||
|
||||
})
|
||||
|
||||
func createSignalClient(addr string, key wgtypes.Key) *signal.Client {
|
||||
func createSignalClient(addr string, key wgtypes.Key) *Client {
|
||||
var sigTLSEnabled = false
|
||||
client, err := signal.NewClient(context.Background(), addr, key, sigTLSEnabled)
|
||||
client, err := NewClient(context.Background(), addr, key, sigTLSEnabled)
|
||||
if err != nil {
|
||||
Fail("failed creating signal client")
|
||||
}
|
||||
@ -173,7 +173,7 @@ func startSignal() (*grpc.Server, net.Listener) {
|
||||
panic(err)
|
||||
}
|
||||
s := grpc.NewServer()
|
||||
sigProto.RegisterSignalExchangeServer(s, signal.NewServer())
|
||||
sigProto.RegisterSignalExchangeServer(s, server.NewServer())
|
||||
go func() {
|
||||
if err := s.Serve(lis); err != nil {
|
||||
log.Fatalf("failed to serve: %v", err)
|
@ -1,41 +0,0 @@
|
||||
package signal
|
||||
|
||||
import (
|
||||
"github.com/wiretrustee/wiretrustee/encryption"
|
||||
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestEncryptDecrypt(t *testing.T) {
|
||||
strMsg := "message to encrypt"
|
||||
bytesMsg := []byte(strMsg)
|
||||
|
||||
peerAKey, err := wgtypes.GenerateKey()
|
||||
if err != nil {
|
||||
t.Error()
|
||||
return
|
||||
}
|
||||
|
||||
peerBKey, err := wgtypes.GenerateKey()
|
||||
if err != nil {
|
||||
t.Error()
|
||||
return
|
||||
}
|
||||
|
||||
encryptedMessage, err := encryption.Encrypt(bytesMsg, peerBKey.PublicKey(), peerAKey)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
decryptedMessage, err := encryption.Decrypt(encryptedMessage, peerAKey.PublicKey(), peerBKey)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
if string(decryptedMessage) != strMsg {
|
||||
t.Error()
|
||||
}
|
||||
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
package signal
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
)
|
||||
|
||||
const (
|
||||
// HexTable Table of Hexadecimal chars
|
||||
HexTable = "0123456789abcdef"
|
||||
)
|
||||
|
||||
// FingerPrint generates a SHA256 Fingerprint of the string
|
||||
func FingerPrint(key string) string {
|
||||
hasher := sha256.New()
|
||||
hasher.Write([]byte(key))
|
||||
sha := hasher.Sum(nil)
|
||||
return hex.EncodeToString(sha)
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package signal
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
Loading…
Reference in New Issue
Block a user