From 0279bdad7cc690b2a39a4b7d68dc94903d9fe46a Mon Sep 17 00:00:00 2001 From: eyedeekay Date: Sun, 23 Feb 2025 18:19:09 -0500 Subject: [PATCH] start on a wrapper for sam3 --- common/emitter_test.go | 132 ----------------------------------------- datagram/datagram.go | 2 +- 2 files changed, 1 insertion(+), 133 deletions(-) delete mode 100644 common/emitter_test.go diff --git a/common/emitter_test.go b/common/emitter_test.go deleted file mode 100644 index 4d073909c..000000000 --- a/common/emitter_test.go +++ /dev/null @@ -1,132 +0,0 @@ -package common - -import ( - "bytes" - "testing" -) - -var ( - from = RandPort() - to = RandPort() -) - -func setupTestEmit() *SAMEmit { - return &SAMEmit{ - I2PConfig: I2PConfig{ - SamHost: "127.0.0.1", - SamPort: 7656, - SamMin: "3.0", - SamMax: "3.1", - Style: "STREAM", - TunName: "testid", - Fromport: from, - Toport: to, - SigType: "ED25519", - }, - } -} - -func TestSAMEmit_Hello(t *testing.T) { - emit := setupTestEmit() - want := "HELLO VERSION MIN=3.0 MAX=3.1 \n" - - t.Run("string output", func(t *testing.T) { - if got := emit.Hello(); got != want { - t.Errorf("Hello() = %v, want %v", got, want) - } - }) - - t.Run("byte output", func(t *testing.T) { - if got := emit.HelloBytes(); !bytes.Equal(got, []byte(want)) { - t.Errorf("HelloBytes() = %v, want %v", got, []byte(want)) - } - }) -} - -func TestSAMEmit_GenerateDestination(t *testing.T) { - emit := setupTestEmit() - want := "DEST GENERATE ED25519 \n" - - t.Run("string output", func(t *testing.T) { - if got := emit.GenerateDestination(); got != want { - t.Errorf("GenerateDestination() = %v, want %v", got, want) - } - }) - - t.Run("byte output", func(t *testing.T) { - if got := emit.GenerateDestinationBytes(); !bytes.Equal(got, []byte(want)) { - t.Errorf("GenerateDestinationBytes() = %v, want %v", got, []byte(want)) - } - }) -} - -func TestSAMEmit_Lookup(t *testing.T) { - tests := []struct { - name string - lookup string - want string - }{ - {"basic lookup", "test.i2p", "NAMING LOOKUP NAME=test.i2p \n"}, - {"empty lookup", "", "NAMING LOOKUP NAME= \n"}, - } - - emit := setupTestEmit() - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if got := emit.Lookup(tt.lookup); got != tt.want { - t.Errorf("Lookup() = %v, want %v", got, tt.want) - } - if got := emit.LookupBytes(tt.lookup); !bytes.Equal(got, []byte(tt.want)) { - t.Errorf("LookupBytes() = %v, want %v", got, []byte(tt.want)) - } - }) - } -} - -func TestSAMEmit_Connect(t *testing.T) { - tests := []struct { - name string - dest string - want string - }{ - { - "basic connect", - "destination123", - "STREAM CONNECT ID=testid " + from + " " + to + " DESTINATION=destination123 \n", - }, - { - "empty destination", - "", - "STREAM CONNECT ID=testid " + from + " " + to + " DESTINATION= \n", - }, - } - - emit := setupTestEmit() - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if got := emit.Connect(tt.dest); got != tt.want { - t.Errorf("Connect() = %v, want %v", got, tt.want) - } - if got := emit.ConnectBytes(tt.dest); !bytes.Equal(got, []byte(tt.want)) { - t.Errorf("ConnectBytes() = %v, want %v", got, []byte(tt.want)) - } - }) - } -} - -func TestSAMEmit_Accept(t *testing.T) { - emit := setupTestEmit() - want := "STREAM ACCEPT ID=testid " + from + " " + to + "" - - t.Run("string output", func(t *testing.T) { - if got := emit.Accept(); got != want { - t.Errorf("Accept() = %v, want %v", got, want) - } - }) - - t.Run("byte output", func(t *testing.T) { - if got := emit.AcceptBytes(); !bytes.Equal(got, []byte(want)) { - t.Errorf("AcceptBytes() = %v, want %v", got, []byte(want)) - } - }) -} diff --git a/datagram/datagram.go b/datagram/datagram.go index 40cfcb694..e3604115a 100644 --- a/datagram/datagram.go +++ b/datagram/datagram.go @@ -12,7 +12,7 @@ import ( // Creates a new datagram session. udpPort is the UDP port SAM is listening on, // and if you set it to zero, it will use SAMs standard UDP port. -func (s *SAM) NewDatagramSession(id string, keys i2pkeys.I2PKeys, options []string, udpPort int) (*DatagramSession, error) { +func (s SAM) NewDatagramSession(id string, keys i2pkeys.I2PKeys, options []string, udpPort int) (*DatagramSession, error) { log.WithFields(logrus.Fields{ "id": id, "udpPort": udpPort,