work on datagram support. add the ability to get the private keys from the client.

This commit is contained in:
idk
2022-06-02 23:56:49 -04:00
parent 6eca8863f7
commit cfdb60d932
3 changed files with 73 additions and 19 deletions

View File

@ -27,8 +27,8 @@ type Client struct {
user string user string
pass string pass string
SamConn net.Conn // Control socket SamConn net.Conn // Control socket
SamDGConn DatagramConn // Datagram socket SamDGConn net.PacketConn // Datagram socket
rd *bufio.Reader rd *bufio.Reader
// d *Client // d *Client
@ -206,6 +206,13 @@ func (p *Client) LocalAddr() net.Addr {
return p.Addr() return p.Addr()
} }
// LocalKeys returns the local keys of the client as a fully-fledged i2pkeys.I2PKeys
func (p *Client) PrivateAddr() i2pkeys.I2PKeys {
//keys := i2pkeys.I2PAddr(p.Destination())
keys := i2pkeys.NewKeys(i2pkeys.I2PAddr(p.base64()), p.Destination())
return keys
}
//return the combined host:port of the SAM bridge //return the combined host:port of the SAM bridge
func (c *Client) samaddr() string { func (c *Client) samaddr() string {
return fmt.Sprintf("%s:%s", c.host, c.port) return fmt.Sprintf("%s:%s", c.host, c.port)

View File

@ -6,20 +6,56 @@ import (
) )
// DatagramConn // DatagramConn
type DatagramConn interface { type DatagramConn struct {
ReadFrom(p []byte) (n int, addr net.Addr, err error) RWC
Read(b []byte) (n int, err error) conn net.PacketConn
WriteTo(p []byte, addr net.Addr) (n int, err error) RAddr net.Addr
Write(b []byte) (n int, err error)
Close() error
LocalAddr() net.Addr
RemoteAddr() net.Addr
SetDeadline(t time.Time) error
SetReadDeadline(t time.Time) error
SetWriteDeadline(t time.Time) error
} }
/** // WrapConn wraps a net.PacketConn in a DatagramConn.
* When datagram support is finished, this will compile. func WrapPacketConn(c net.Conn) *Conn {
* var conn DatagramConn = &Client{} wrap := Conn{
**/ conn: c,
}
wrap.Reader = NewReadLogger("<", c)
wrap.Writer = NewWriteLogger(">", c)
wrap.RWC.c = c
return &wrap
}
func (d *DatagramConn) ReadFrom(p []byte) (n int, addr net.Addr, err error) {
return d.conn.ReadFrom(p)
}
func (d *DatagramConn) Read(b []byte) (n int, err error) {
n, _, err = d.ReadFrom(b)
return n, err
}
func (d *DatagramConn) WriteTo(p []byte, addr net.Addr) (n int, err error) {
return d.conn.WriteTo(p, addr)
}
func (d *DatagramConn) Write(b []byte) (n int, err error) {
n, err = d.WriteTo(b, d.RemoteAddr())
return n, err
}
func (d *DatagramConn) Close() error {
return d.conn.Close()
}
func (d *DatagramConn) LocalAddr() net.Addr {
return d.conn.LocalAddr()
}
func (d *DatagramConn) RemoteAddr() net.Addr {
return d.RAddr
}
func (d *DatagramConn) SetDeadline(t time.Time) error {
return d.conn.SetDeadline(t)
}
func (d *DatagramConn) SetReadDeadline(t time.Time) error {
return d.conn.SetReadDeadline(t)
}
func (d *DatagramConn) SetWriteDeadline(t time.Time) error {
return d.conn.SetWriteDeadline(t)
}
var dgt net.PacketConn = &DatagramConn{}
//func (c *Client) DatagramSend()

15
dial.go
View File

@ -39,7 +39,7 @@ func (c *Client) Dial(network, addr string) (net.Conn, error) {
return c.DialContext(context.TODO(), network, addr) return c.DialContext(context.TODO(), network, addr)
} }
// Dial implements the net.Dial function and can be used for http.Transport // DialContextFree implements the net.Dial function and can be used for http.Transport
func (c *Client) DialContextFree(network, addr string) (net.Conn, error) { func (c *Client) DialContextFree(network, addr string) (net.Conn, error) {
if network == "tcp" || network == "tcp6" || network == "tcp4" { if network == "tcp" || network == "tcp6" || network == "tcp4" {
return c.DialStreamingContextFree(addr) return c.DialStreamingContextFree(addr)
@ -55,10 +55,21 @@ func (c *Client) DialContextFree(network, addr string) (net.Conn, error) {
// DialDatagramContextFree is a "Dialer" for "Client-Like" Datagram connections. // DialDatagramContextFree is a "Dialer" for "Client-Like" Datagram connections.
// It is also not finished. If you need datagram support right now, use sam3. // It is also not finished. If you need datagram support right now, use sam3.
func (c *Client) DialDatagramContextFree(addr string) (DatagramConn, error) { func (c *Client) DialDatagramContextFree(addr string) (*DatagramConn, error) {
portIdx := strings.Index(addr, ":")
if portIdx >= 0 {
addr = addr[:portIdx]
}
addr, err := c.Lookup(addr)
if err != nil {
log.Printf("LOOKUP DIALER ERROR %s %s", addr, err)
return nil, err
}
return nil, fmt.Errorf("Datagram support is not finished yet, come back later`") return nil, fmt.Errorf("Datagram support is not finished yet, come back later`")
} }
// DialStreamingContextFree is a "Dialer" for "Client-Like" Streaming connections.
func (c *Client) DialStreamingContextFree(addr string) (net.Conn, error) { func (c *Client) DialStreamingContextFree(addr string) (net.Conn, error) {
portIdx := strings.Index(addr, ":") portIdx := strings.Index(addr, ":")
if portIdx >= 0 { if portIdx >= 0 {