diff --git a/Makefile b/Makefile index aa10913..57637fb 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ USER_GH=eyedeekay -VERSION=0.32.30 +VERSION=0.32.4 packagename=gosam echo: fmt diff --git a/accept.go b/accept.go index 5c92805..d3ecb0c 100644 --- a/accept.go +++ b/accept.go @@ -25,18 +25,11 @@ 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 - } - c.destination = d - if c.debug { c.SamConn = WrapConn(c.SamConn) } diff --git a/client.go b/client.go index d57c041..4716e45 100644 --- a/client.go +++ b/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 @@ -60,6 +62,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 +182,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 diff --git a/conn.go b/conn.go index 798bb95..497d54c 100644 --- a/conn.go +++ b/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) diff --git a/datagram.go b/datagram.go index 80b7abc..a42b712 100644 --- a/datagram.go +++ b/datagram.go @@ -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{} + + +*/ diff --git a/dial.go b/dial.go index ccc34b1..97014fd 100644 --- a/dial.go +++ b/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) {