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
pass string
SamConn net.Conn // Control socket
SamDGConn DatagramConn // Datagram socket
SamConn net.Conn // Control socket
SamDGConn net.PacketConn // Datagram socket
rd *bufio.Reader
// d *Client
@ -206,6 +206,13 @@ func (p *Client) LocalAddr() net.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
func (c *Client) samaddr() string {
return fmt.Sprintf("%s:%s", c.host, c.port)

View File

@ -6,20 +6,56 @@ import (
)
// DatagramConn
type DatagramConn interface {
ReadFrom(p []byte) (n int, addr net.Addr, err error)
Read(b []byte) (n int, err error)
WriteTo(p []byte, addr net.Addr) (n int, err error)
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
type DatagramConn struct {
RWC
conn net.PacketConn
RAddr net.Addr
}
/**
* When datagram support is finished, this will compile.
* var conn DatagramConn = &Client{}
**/
// WrapConn wraps a net.PacketConn in a DatagramConn.
func WrapPacketConn(c net.Conn) *Conn {
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)
}
// 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) {
if network == "tcp" || network == "tcp6" || network == "tcp4" {
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.
// 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`")
}
// DialStreamingContextFree is a "Dialer" for "Client-Like" Streaming connections.
func (c *Client) DialStreamingContextFree(addr string) (net.Conn, error) {
portIdx := strings.Index(addr, ":")
if portIdx >= 0 {