more debugging
This commit is contained in:
parent
e5f26a25da
commit
ce09953167
|
@ -1,6 +1,7 @@
|
|||
package telebit
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
)
|
||||
|
||||
|
@ -29,12 +30,13 @@ func (d *Decoder) Decode(out Router) error {
|
|||
go func() {
|
||||
for {
|
||||
b := make([]byte, d.bufferSize)
|
||||
//fmt.Println("loopers gonna loop")
|
||||
n, err := d.in.Read(b)
|
||||
fmt.Println("[debug] [decoder] [srv] Tunnel read", n)
|
||||
if n > 0 {
|
||||
rx <- b[:n]
|
||||
}
|
||||
if nil != err {
|
||||
fmt.Println("[debug] [decoder] [srv] Tunnel read err", err)
|
||||
rxErr <- err
|
||||
return
|
||||
}
|
||||
|
@ -47,8 +49,10 @@ func (d *Decoder) Decode(out Router) error {
|
|||
// TODO, do we actually need ctx here?
|
||||
// would it be sufficient to expect the reader to be closed by the caller instead?
|
||||
case b := <-rx:
|
||||
fmt.Println("[debug] [decoder] [srv] Tunnel write", len(b), string(b))
|
||||
_, err := p.Write(b)
|
||||
if nil != err {
|
||||
fmt.Println("[debug] [decoder] [srv] Tunnel write error")
|
||||
// an error to write represents an unrecoverable error,
|
||||
// not just a downstream client error
|
||||
//d.in.Close()
|
||||
|
|
|
@ -2,7 +2,9 @@ package telebit
|
|||
|
||||
import (
|
||||
"context"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"sync"
|
||||
)
|
||||
|
@ -71,10 +73,12 @@ func (enc *Encoder) Encode(rin io.Reader, src, dst Addr) error {
|
|||
b := make([]byte, enc.bufferSize)
|
||||
//fmt.Println("loopers gonna loop")
|
||||
n, err := rin.Read(b)
|
||||
fmt.Println("[debug] [encoder] [srv] Browser read", n)
|
||||
if n > 0 {
|
||||
rx <- b[:n]
|
||||
}
|
||||
if nil != err {
|
||||
fmt.Println("[debug] [encoder] [srv] Browser read error", err)
|
||||
rxErr <- err
|
||||
return
|
||||
}
|
||||
|
@ -90,21 +94,27 @@ func (enc *Encoder) Encode(rin io.Reader, src, dst Addr) error {
|
|||
case <-enc.ctx.Done():
|
||||
// TODO: verify that closing the reader will cause the goroutine to be released
|
||||
//rin.Close()
|
||||
fmt.Println("[debug] [encoder] [srv] Browser ctx.Done()")
|
||||
return errors.New("cancelled by encoder read or parent context")
|
||||
case <-enc.subctx.Done():
|
||||
//rin.Close()
|
||||
fmt.Println("[debug] [encoder] [srv] Browser subctx.Done()")
|
||||
return errors.New("cancelled by encoder write context")
|
||||
case b := <-rx:
|
||||
header, _, err := Encode(b, src, Addr{scheme: src.scheme, addr: "", port: -1})
|
||||
header, _, err := Encode(b, src, Addr{scheme: src.scheme, addr: dst.Hostname(), port: dst.Port()})
|
||||
if nil != err {
|
||||
//rin.Close()
|
||||
fmt.Println("[debug] [encoder] [srv] Browser Encode err", err)
|
||||
return err
|
||||
}
|
||||
//fmt.Println("[debug] encode header:", string(header))
|
||||
//fmt.Println("[debug] encode payload:", string(b))
|
||||
|
||||
_, err = enc.write(header, b)
|
||||
fmt.Println("[debug] [encoder] [srv] Browser-to-tun write", len(header), header)
|
||||
fmt.Println("[debug] [encoder] [srv]", len(b), hex.EncodeToString(b))
|
||||
if nil != err {
|
||||
fmt.Println("[debug] [encoder] [srv] Browser-to-tun write err", err)
|
||||
//rin.Close()
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ func (p *Parser) unpackV1(b []byte) (int, error) {
|
|||
z++
|
||||
n := len(b)
|
||||
if n < 1 {
|
||||
//fmt.Println("[debug] v1 end", z, n)
|
||||
fmt.Printf("[debug] v1 message unpacked (%d loops) (%d bytes left)\n", z, n)
|
||||
break
|
||||
}
|
||||
|
||||
|
@ -141,7 +141,10 @@ func (p *Parser) unpackV1Header(b []byte, n int) ([]byte, error) {
|
|||
port, _ := strconv.Atoi(parts[PortIndex])
|
||||
service := parts[ServiceIndex]
|
||||
|
||||
fmt.Printf("[debug] parts: %s\n", parts)
|
||||
fmt.Printf("[debug] service: %s\n", service)
|
||||
if "control" == service {
|
||||
fmt.Printf("[debug] control: %s\n", service)
|
||||
return nil, errors.New("'control' messages not implemented")
|
||||
}
|
||||
|
||||
|
@ -163,6 +166,7 @@ func (p *Parser) unpackV1Header(b []byte, n int) ([]byte, error) {
|
|||
}
|
||||
p.state.srcAddr = src
|
||||
p.state.dstAddr = dst
|
||||
|
||||
/*
|
||||
p.state.conn = p.conns[addr.Network()]
|
||||
if nil == p.state.conn {
|
||||
|
@ -180,11 +184,16 @@ func (p *Parser) unpackV1Header(b []byte, n int) ([]byte, error) {
|
|||
}
|
||||
*/
|
||||
p.parseState++
|
||||
fmt.Printf("[debug] parse state: %v\n", p.parseState)
|
||||
|
||||
if "end" == service {
|
||||
p.handler.RouteBytes(p.state.srcAddr, p.state.dstAddr, []byte{})
|
||||
}
|
||||
return b, nil
|
||||
}
|
||||
|
||||
func (p *Parser) unpackV1Payload(b []byte, n int) ([]byte, error) {
|
||||
fmt.Printf("[debug] state: %+v\n", p.state)
|
||||
// Handle "connect" and "end"
|
||||
if 0 == p.state.payloadLen {
|
||||
/*
|
||||
|
@ -203,6 +212,7 @@ func (p *Parser) unpackV1Payload(b []byte, n int) ([]byte, error) {
|
|||
*/
|
||||
|
||||
//fmt.Printf("[debug] [2] payload written: %d | payload length: %d\n", p.state.payloadWritten, p.state.payloadLen)
|
||||
fmt.Printf("[debug] RouteBytes: %#v %#v %s\n", p.state.srcAddr, p.state.dstAddr, p.state.dstAddr.scheme)
|
||||
p.handler.RouteBytes(p.state.srcAddr, p.state.dstAddr, []byte{})
|
||||
return b, nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue