Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
0623ed8a79 | ||
![]() |
964219c25f | ||
![]() |
23c45022b3 |
2
Makefile
2
Makefile
@@ -1,6 +1,6 @@
|
||||
|
||||
USER_GH=eyedeekay
|
||||
VERSION=0.32.30
|
||||
VERSION=0.32.5
|
||||
packagename=gosam
|
||||
|
||||
echo: fmt
|
||||
|
15
accept.go
15
accept.go
@@ -25,23 +25,24 @@ func (c *Client) Listen() (net.Listener, error) {
|
||||
func (c *Client) ListenI2P(dest string) (net.Listener, error) {
|
||||
var err error
|
||||
c.destination, err = c.CreateStreamSession(dest)
|
||||
d := c.destination
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
fmt.Println("Listening on destination:", c.Base32()+".b32.i2p")
|
||||
|
||||
c, err = c.NewClient(c.id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
if c.d == nil {
|
||||
c.d, err = c.NewClient(c.NewID())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
c.destination = d
|
||||
|
||||
fmt.Println("Listening on destination:", c.Base32()+".b32.i2p")
|
||||
|
||||
if c.debug {
|
||||
c.SamConn = WrapConn(c.SamConn)
|
||||
}
|
||||
|
||||
return c, nil
|
||||
return c.d, nil
|
||||
}
|
||||
|
||||
// Accept accepts a connection on a listening goSam.Client(Implements net.Listener)
|
||||
|
20
client.go
20
client.go
@@ -13,6 +13,8 @@ import (
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
samkeys "github.com/eyedeekay/goSam/compat"
|
||||
)
|
||||
|
||||
// A Client represents a single Connection to the SAM bridge
|
||||
@@ -22,9 +24,10 @@ type Client struct {
|
||||
fromport string
|
||||
toport string
|
||||
|
||||
SamConn net.Conn
|
||||
SamDGConn DatagramConn
|
||||
SamConn net.Conn // Control socket
|
||||
SamDGConn DatagramConn // Datagram socket
|
||||
rd *bufio.Reader
|
||||
d *Client
|
||||
|
||||
sigType string
|
||||
destination string
|
||||
@@ -60,6 +63,7 @@ type Client struct {
|
||||
sammax int
|
||||
}
|
||||
|
||||
// SAMsigTypes is a slice of the available signature types
|
||||
var SAMsigTypes = []string{
|
||||
"SIGNATURE_TYPE=DSA_SHA1",
|
||||
"SIGNATURE_TYPE=ECDSA_SHA256_P256",
|
||||
@@ -179,12 +183,22 @@ func NewClientFromOptions(opts ...func(*Client) error) (*Client, error) {
|
||||
return &c, c.hello()
|
||||
}
|
||||
|
||||
// ID returns a the current ID of the client as a string
|
||||
func (p *Client) ID() string {
|
||||
return fmt.Sprintf("%d", p.NewID())
|
||||
}
|
||||
|
||||
// Addr returns the address of the client as a net.Addr
|
||||
func (p *Client) Addr() net.Addr {
|
||||
return nil
|
||||
keys, err := samkeys.DestToKeys(p.Destination())
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
return keys.Addr()
|
||||
}
|
||||
|
||||
func (p *Client) LocalAddr() net.Addr {
|
||||
return p.Addr()
|
||||
}
|
||||
|
||||
//return the combined host:port of the SAM bridge
|
||||
|
@@ -1,3 +1,4 @@
|
||||
//go:build nettest
|
||||
// +build nettest
|
||||
|
||||
package goSam
|
||||
@@ -45,7 +46,7 @@ func TestCompositeClient(t *testing.T) {
|
||||
// http.HandleFunc("/", HelloServer)
|
||||
go http.Serve(listener3, nil)
|
||||
|
||||
sam, err := NewClientFromOptions(SetDebug(false))
|
||||
sam, err := NewClientFromOptions(SetDebug(true))
|
||||
if err != nil {
|
||||
t.Fatalf("NewDefaultClient() Error: %q\n", err)
|
||||
}
|
||||
@@ -83,7 +84,7 @@ func TestCompositeClient(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestClientHello(t *testing.T) {
|
||||
client, err := NewClientFromOptions(SetDebug(false))
|
||||
client, err := NewClientFromOptions(SetDebug(true))
|
||||
if err != nil {
|
||||
t.Fatalf("NewDefaultClient() Error: %q\n", err)
|
||||
}
|
||||
@@ -94,7 +95,7 @@ func TestClientHello(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNewDestination(t *testing.T) {
|
||||
client, err := NewClientFromOptions(SetDebug(false))
|
||||
client, err := NewClientFromOptions(SetDebug(true))
|
||||
if err != nil {
|
||||
t.Fatalf("NewDefaultClient() Error: %q\n", err)
|
||||
}
|
||||
|
9
conn.go
9
conn.go
@@ -30,11 +30,14 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// Conn Read data from the connection, writes data to te connection
|
||||
// and logs the data in-between.
|
||||
type Conn struct {
|
||||
RWC
|
||||
conn net.Conn
|
||||
}
|
||||
|
||||
// WrapConn wraps a net.Conn in a Conn.
|
||||
func WrapConn(c net.Conn) *Conn {
|
||||
wrap := Conn{
|
||||
conn: c,
|
||||
@@ -45,23 +48,29 @@ func WrapConn(c net.Conn) *Conn {
|
||||
return &wrap
|
||||
}
|
||||
|
||||
// LocalAddr returns the local address of the connection.
|
||||
func (c *Conn) LocalAddr() net.Addr {
|
||||
return c.conn.LocalAddr()
|
||||
}
|
||||
|
||||
// RemoteAddr returns the remote address of the connection.
|
||||
func (c *Conn) RemoteAddr() net.Addr {
|
||||
return c.conn.RemoteAddr()
|
||||
}
|
||||
|
||||
// SetDeadline sets the read and write deadlines associated with the connection
|
||||
func (c *Conn) SetDeadline(t time.Time) error {
|
||||
log.Println("WARNING: SetDeadline() not sure this works")
|
||||
return c.conn.SetDeadline(t)
|
||||
}
|
||||
|
||||
// SetReadDeadline sets the read deadline associated with the connection
|
||||
func (c *Conn) SetReadDeadline(t time.Time) error {
|
||||
log.Println("WARNING: SetReadDeadline() not sure this works")
|
||||
return c.conn.SetReadDeadline(t)
|
||||
}
|
||||
|
||||
// SetWriteDeadline sets the write deadline associated with the connection
|
||||
func (c *Conn) SetWriteDeadline(t time.Time) error {
|
||||
log.Println("WARNING: SetWriteDeadline() not sure this works")
|
||||
return c.conn.SetWriteDeadline(t)
|
||||
|
@@ -5,6 +5,7 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// DatagramConn
|
||||
type DatagramConn interface {
|
||||
ReadFrom(p []byte) (n int, addr net.Addr, err error)
|
||||
Read(b []byte) (n int, err error)
|
||||
@@ -17,3 +18,9 @@ type DatagramConn interface {
|
||||
SetReadDeadline(t time.Time) error
|
||||
SetWriteDeadline(t time.Time) error
|
||||
}
|
||||
|
||||
/**
|
||||
var conn DatagramConn = &Client{}
|
||||
|
||||
|
||||
*/
|
||||
|
19
dial.go
19
dial.go
@@ -2,6 +2,7 @@ package goSam
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"strings"
|
||||
@@ -52,8 +53,10 @@ func (c *Client) DialContextFree(network, addr string) (net.Conn, error) {
|
||||
return c.DialStreamingContextFree(addr)
|
||||
}
|
||||
|
||||
// DialDatagramContextFree is a "Dialer" for "Client-Like" Datagram connections.
|
||||
// It is also not finished. If you need datagram support right now, use sam3.
|
||||
func (c *Client) DialDatagramContextFree(addr string) (DatagramConn, error) {
|
||||
return c.SamDGConn, nil
|
||||
return nil, fmt.Errorf("Datagram support is not finished yet, come back later`")
|
||||
}
|
||||
|
||||
func (c *Client) DialStreamingContextFree(addr string) (net.Conn, error) {
|
||||
@@ -73,14 +76,16 @@ func (c *Client) DialStreamingContextFree(addr string) (net.Conn, error) {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if c.d == nil {
|
||||
c.d, err = c.NewClient(c.NewID())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
d, err := c.NewClient(c.NewID())
|
||||
err = c.d.StreamConnect(addr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = d.StreamConnect(addr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return d.SamConn, nil
|
||||
return c.d.SamConn, nil
|
||||
}
|
||||
|
@@ -1,3 +1,4 @@
|
||||
//go:build nettest
|
||||
// +build nettest
|
||||
|
||||
package goSam
|
||||
@@ -10,7 +11,7 @@ import (
|
||||
func TestClientLookupInvalid(t *testing.T) {
|
||||
var err error
|
||||
|
||||
client, err := NewClientFromOptions(SetDebug(false))
|
||||
client, err := NewClientFromOptions(SetDebug(true))
|
||||
if err != nil {
|
||||
t.Fatalf("NewDefaultClient() Error: %q\n", err)
|
||||
}
|
||||
|
@@ -1,3 +1,4 @@
|
||||
//go:build nettest
|
||||
// +build nettest
|
||||
|
||||
package goSam
|
||||
@@ -36,7 +37,7 @@ func (c *Client) validCreate() (string, error) {
|
||||
}
|
||||
|
||||
func TestOptionAddrString(t *testing.T) {
|
||||
client, err := NewClientFromOptions(SetAddr("127.0.0.1:7656"), SetDebug(false))
|
||||
client, err := NewClientFromOptions(SetAddr("127.0.0.1:7656"), SetDebug(true))
|
||||
if err != nil {
|
||||
t.Fatalf("NewClientFromOptions() Error: %q\n", err)
|
||||
}
|
||||
@@ -55,7 +56,7 @@ func TestOptionAddrString(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestOptionAddrStringLh(t *testing.T) {
|
||||
client, err := NewClientFromOptions(SetAddr("localhost:7656"), SetDebug(false))
|
||||
client, err := NewClientFromOptions(SetAddr("localhost:7656"), SetDebug(true))
|
||||
if err != nil {
|
||||
t.Fatalf("NewClientFromOptions() Error: %q\n", err)
|
||||
}
|
||||
@@ -74,7 +75,7 @@ func TestOptionAddrStringLh(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestOptionAddrSlice(t *testing.T) {
|
||||
client, err := NewClientFromOptions(SetAddr("127.0.0.1", "7656"), SetDebug(false))
|
||||
client, err := NewClientFromOptions(SetAddr("127.0.0.1", "7656"), SetDebug(true))
|
||||
if err != nil {
|
||||
t.Fatalf("NewClientFromOptions() Error: %q\n", err)
|
||||
}
|
||||
@@ -93,7 +94,7 @@ func TestOptionAddrSlice(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestOptionAddrMixedSlice(t *testing.T) {
|
||||
client, err := NewClientFromOptions(SetAddrMixed("127.0.0.1", 7656), SetDebug(false))
|
||||
client, err := NewClientFromOptions(SetAddrMixed("127.0.0.1", 7656), SetDebug(true))
|
||||
if err != nil {
|
||||
t.Fatalf("NewClientFromOptions() Error: %q\n", err)
|
||||
}
|
||||
@@ -124,7 +125,7 @@ func TestOptionHost(t *testing.T) {
|
||||
SetInBackups(2),
|
||||
SetOutBackups(2),
|
||||
SetEncrypt(true),
|
||||
SetDebug(false),
|
||||
SetDebug(true),
|
||||
SetUnpublished(true),
|
||||
SetReduceIdle(true),
|
||||
SetReduceIdleTime(300001),
|
||||
@@ -162,7 +163,7 @@ func TestOptionPortInt(t *testing.T) {
|
||||
SetInBackups(2),
|
||||
SetOutBackups(2),
|
||||
SetEncrypt(true),
|
||||
SetDebug(false),
|
||||
SetDebug(true),
|
||||
SetUnpublished(true),
|
||||
SetReduceIdle(true),
|
||||
SetReduceIdleTime(300001),
|
||||
|
@@ -11,8 +11,9 @@ func init() {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
}
|
||||
|
||||
// CreateSession creates a new STREAM Session.
|
||||
// Returns the Id for the new Client.
|
||||
// CreateSession creates a new Session of type style, with an optional destination.
|
||||
// an empty destination is interpreted as "TRANSIENT"
|
||||
// Returns the destination for the new Client or an error.
|
||||
func (c *Client) CreateSession(style, dest string) (string, error) {
|
||||
if dest == "" {
|
||||
dest = "TRANSIENT"
|
||||
|
Reference in New Issue
Block a user