4 Commits
v0.32.52 ... dg

Author SHA1 Message Date
idk
55d40a2238 Use the connection wrapper to implement a Datagram based connection, hopefully 2021-04-15 20:24:43 -04:00
idk
b47be771d5 Use the connection wrapper to implement a Datagram based connection, hopefully 2021-04-15 20:19:55 -04:00
idk
8fcab6ce00 Don't delay the test 2021-04-15 19:35:19 -04:00
idk
3760249a67 Don't delay the test 2021-04-15 19:35:02 -04:00
8 changed files with 38 additions and 26 deletions

View File

@@ -37,9 +37,7 @@ func (c *Client) ListenI2P(dest string) (net.Listener, error) {
}
c.destination = d
if c.debug {
c.SamConn = WrapConn(c.SamConn)
}
c.SamConn = WrapConn(c.SamConn, c.ID(), fmt.Sprintf("3.%d", c.sammax), c.debug)
return c, nil
}

View File

@@ -22,9 +22,8 @@ type Client struct {
fromport string
toport string
SamConn net.Conn
SamDGConn DatagramConn
rd *bufio.Reader
SamConn *Conn
rd *bufio.Reader
sigType string
destination string
@@ -171,10 +170,7 @@ func NewClientFromOptions(opts ...func(*Client) error) (*Client, error) {
if err != nil {
return nil, err
}
if c.debug {
conn = WrapConn(conn)
}
c.SamConn = conn
c.SamConn = WrapConn(conn, c.ID(), fmt.Sprintf("3.%d", c.sammax), c.debug)
c.rd = bufio.NewReader(conn)
return &c, c.hello()
}

View File

@@ -62,7 +62,7 @@ func TestCompositeClient(t *testing.T) {
}
defer resp.Body.Close()
}()
time.Sleep(time.Second * 15)
// time.Sleep(time.Second * 15)
go func() {
resp, err := client.Get("http://" + listener2.Addr().(i2pkeys.I2PAddr).Base32())
if err != nil {
@@ -70,7 +70,7 @@ func TestCompositeClient(t *testing.T) {
}
defer resp.Body.Close()
}()
time.Sleep(time.Second * 15)
// time.Sleep(time.Second * 15)
go func() {
resp, err := client.Get("http://" + listener3.Addr().(i2pkeys.I2PAddr).Base32())
if err != nil {

27
conn.go
View File

@@ -32,15 +32,22 @@ import (
type Conn struct {
RWC
conn net.Conn
id string
version string
conn net.Conn
}
func WrapConn(c net.Conn) *Conn {
var streamingConn net.Conn = Conn
var datagramConn net.PacketConn = Conn
func WrapConn(c net.Conn, id, version string, debug bool) *Conn {
wrap := Conn{
conn: c,
conn: c,
id: id,
version: version,
}
wrap.Reader = NewReadLogger("<", c)
wrap.Writer = NewWriteLogger(">", c)
wrap.Reader = NewReadLogger("<", debug, c)
wrap.Writer = NewWriteLogger(">", debug, c)
wrap.RWC.c = c
return &wrap
}
@@ -53,6 +60,16 @@ func (c *Conn) RemoteAddr() net.Addr {
return c.conn.RemoteAddr()
}
func (c *Conn) ReadFrom(b []byte) (int, net.Addr, error) {
return c.ReadFrom(b)
}
func (c *Conn) WriteTo(b []byte, addr net.Addr) (int, error) {
header := []byte(c.version + " " + c.id + " " + addr.String() + "\n")
msg := append(header, b...)
return c.WriteTo(msg, addr)
}
func (c *Conn) SetDeadline(t time.Time) error {
log.Println("WARNING: SetDeadline() not sure this works")
return c.conn.SetDeadline(t)

View File

@@ -53,7 +53,7 @@ func (c *Client) DialContextFree(network, addr string) (net.Conn, error) {
}
func (c *Client) DialDatagramContextFree(addr string) (DatagramConn, error) {
return c.SamDGConn, nil
return c.SamConn, nil
}
func (c *Client) DialStreamingContextFree(addr string) (net.Conn, error) {

View File

@@ -52,7 +52,6 @@ func (c *Client) forward(client, conn net.Conn) {
}
func (c *Client) Resolve(ctx context.Context, name string) (context.Context, net.IP, error) {
// if c.lastaddr == "invalid" || c.lastaddr != name {
client, err := c.DialContext(ctx, "", name)
if err != nil {
return ctx, nil, err

10
rw.go
View File

@@ -36,6 +36,7 @@ Copy of testing/iotest Read- and WriteLogger, but using %q instead of %x for pri
type writeLogger struct {
prefix string
debug bool
w io.Writer
}
@@ -52,12 +53,13 @@ func (l *writeLogger) Write(p []byte) (n int, err error) {
// NewWriteLogger returns a writer that behaves like w except
// that it logs (using log.Printf) each write to standard error,
// printing the prefix and the hexadecimal data written.
func NewWriteLogger(prefix string, w io.Writer) io.Writer {
return &writeLogger{prefix, w}
func NewWriteLogger(prefix string, debug bool, w io.Writer) io.Writer {
return &writeLogger{prefix, debug, w}
}
type readLogger struct {
prefix string
debug bool
r io.Reader
}
@@ -74,8 +76,8 @@ func (l *readLogger) Read(p []byte) (n int, err error) {
// NewReadLogger returns a reader that behaves like r except
// that it logs (using log.Print) each read to standard error,
// printing the prefix and the hexadecimal data written.
func NewReadLogger(prefix string, r io.Reader) io.Reader {
return &readLogger{prefix, r}
func NewReadLogger(prefix string, debug bool, r io.Reader) io.Reader {
return &readLogger{prefix, debug, r}
}
type readHexLogger struct {

6
rwc.go
View File

@@ -35,9 +35,9 @@ type RWC struct {
c io.Closer
}
func WrapRWC(c io.ReadWriteCloser) io.ReadWriteCloser {
rl := NewReadLogger("<", c)
wl := NewWriteLogger(">", c)
func WrapRWC(c io.ReadWriteCloser, debug bool) io.ReadWriteCloser {
rl := NewReadLogger("<", debug, c)
wl := NewWriteLogger(">", debug, c)
return &RWC{
Reader: rl,