mirror of
https://github.com/tladesignz/dnstt.git
synced 2026-10-03 12:27:55 +03:00
Move dummyAddr to turbotunnel.DummyAddr.
This commit is contained in:
@@ -29,11 +29,11 @@ func NewHTTPPacketConn(urlString string, numSenders int) (*HTTPPacketConn, error
|
||||
client: &http.Client{
|
||||
Timeout: 1 * time.Minute,
|
||||
},
|
||||
QueuePacketConn: turbotunnel.NewQueuePacketConn(dummyAddr{}, 0),
|
||||
QueuePacketConn: turbotunnel.NewQueuePacketConn(turbotunnel.DummyAddr{}, 0),
|
||||
}
|
||||
for i := 0; i < numSenders; i++ {
|
||||
go func() {
|
||||
for p := range c.QueuePacketConn.OutgoingQueue(dummyAddr{}) {
|
||||
for p := range c.QueuePacketConn.OutgoingQueue(turbotunnel.DummyAddr{}) {
|
||||
err := c.send(p)
|
||||
if err != nil {
|
||||
log.Printf("sender thread: %v", err)
|
||||
@@ -55,7 +55,7 @@ func (c *HTTPPacketConn) WriteTo(p []byte, addr net.Addr) (int, error) {
|
||||
}
|
||||
|
||||
// Ignore addr.
|
||||
return c.QueuePacketConn.WriteTo(p, dummyAddr{})
|
||||
return c.QueuePacketConn.WriteTo(p, turbotunnel.DummyAddr{})
|
||||
}
|
||||
|
||||
// send sends a single packet in an HTTP request.
|
||||
@@ -80,7 +80,7 @@ func (c *HTTPPacketConn) send(p []byte) error {
|
||||
}
|
||||
body, err := ioutil.ReadAll(io.LimitReader(resp.Body, 64000))
|
||||
if err == nil {
|
||||
c.QueuePacketConn.QueueIncoming(body, dummyAddr{})
|
||||
c.QueuePacketConn.QueueIncoming(body, turbotunnel.DummyAddr{})
|
||||
}
|
||||
// Ignore err != nil; don't report an error if we at least
|
||||
// managed to send.
|
||||
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
"github.com/xtaci/smux"
|
||||
"www.bamsoftware.com/git/dnstt.git/dns"
|
||||
"www.bamsoftware.com/git/dnstt.git/noise"
|
||||
"www.bamsoftware.com/git/dnstt.git/turbotunnel"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -218,11 +219,6 @@ func run(pubkey []byte, domain dns.Name, localAddr *net.TCPAddr, remoteAddr net.
|
||||
}
|
||||
}
|
||||
|
||||
type dummyAddr struct{}
|
||||
|
||||
func (addr dummyAddr) Network() string { return "dummy" }
|
||||
func (addr dummyAddr) String() string { return "dummy" }
|
||||
|
||||
func main() {
|
||||
var dohURL string
|
||||
var dotAddr string
|
||||
@@ -269,13 +265,13 @@ func main() {
|
||||
}{
|
||||
// -doh
|
||||
{dohURL, func(s string) (net.Addr, net.PacketConn, error) {
|
||||
addr := dummyAddr{}
|
||||
addr := turbotunnel.DummyAddr{}
|
||||
pconn, err := NewHTTPPacketConn(dohURL, 32)
|
||||
return addr, pconn, err
|
||||
}},
|
||||
// -dot
|
||||
{dotAddr, func(s string) (net.Addr, net.PacketConn, error) {
|
||||
addr := dummyAddr{}
|
||||
addr := turbotunnel.DummyAddr{}
|
||||
pconn, err := NewTLSPacketConn(dotAddr)
|
||||
return addr, pconn, err
|
||||
}},
|
||||
|
||||
+4
-4
@@ -17,7 +17,7 @@ type TLSPacketConn struct {
|
||||
|
||||
func NewTLSPacketConn(addr string) (*TLSPacketConn, error) {
|
||||
c := &TLSPacketConn{
|
||||
QueuePacketConn: turbotunnel.NewQueuePacketConn(dummyAddr{}, 0),
|
||||
QueuePacketConn: turbotunnel.NewQueuePacketConn(turbotunnel.DummyAddr{}, 0),
|
||||
}
|
||||
tlsConfig := &tls.Config{}
|
||||
conn, err := tls.Dial("tcp", addr, tlsConfig)
|
||||
@@ -71,12 +71,12 @@ func (c *TLSPacketConn) recvLoop(conn net.Conn) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
c.QueuePacketConn.QueueIncoming(p, dummyAddr{})
|
||||
c.QueuePacketConn.QueueIncoming(p, turbotunnel.DummyAddr{})
|
||||
}
|
||||
}
|
||||
|
||||
func (c *TLSPacketConn) sendLoop(conn net.Conn) error {
|
||||
for p := range c.QueuePacketConn.OutgoingQueue(dummyAddr{}) {
|
||||
for p := range c.QueuePacketConn.OutgoingQueue(turbotunnel.DummyAddr{}) {
|
||||
length := uint16(len(p))
|
||||
if int(length) != len(p) {
|
||||
panic(len(p))
|
||||
@@ -95,5 +95,5 @@ func (c *TLSPacketConn) sendLoop(conn net.Conn) error {
|
||||
|
||||
func (c *TLSPacketConn) WriteTo(p []byte, addr net.Addr) (int, error) {
|
||||
// Ignore addr.
|
||||
return c.QueuePacketConn.WriteTo(p, dummyAddr{})
|
||||
return c.QueuePacketConn.WriteTo(p, turbotunnel.DummyAddr{})
|
||||
}
|
||||
|
||||
@@ -490,11 +490,6 @@ func sendLoop(dnsConn net.PacketConn, ttConn *turbotunnel.QueuePacketConn, ch <-
|
||||
return nil
|
||||
}
|
||||
|
||||
type dummyAddr struct{}
|
||||
|
||||
func (addr dummyAddr) Network() string { return "dummy" }
|
||||
func (addr dummyAddr) String() string { return "dummy" }
|
||||
|
||||
func run(domain dns.Name, upstream net.Addr, udpAddr string) error {
|
||||
privkey, pubkey, err := noise.GenerateKeypair()
|
||||
if err != nil {
|
||||
@@ -504,7 +499,7 @@ func run(domain dns.Name, upstream net.Addr, udpAddr string) error {
|
||||
log.Printf(" pubkey %x", pubkey)
|
||||
|
||||
// Start up the virtual PacketConn for turbotunnel.
|
||||
ttConn := turbotunnel.NewQueuePacketConn(dummyAddr{}, idleTimeout*2)
|
||||
ttConn := turbotunnel.NewQueuePacketConn(turbotunnel.DummyAddr{}, idleTimeout*2)
|
||||
ln, err := kcp.ServeConn(nil, 0, 0, ttConn)
|
||||
if err != nil {
|
||||
return fmt.Errorf("opening KCP listener: %v", err)
|
||||
|
||||
@@ -6,3 +6,11 @@ const queueSize = 64
|
||||
|
||||
var errClosedPacketConn = errors.New("operation on closed connection")
|
||||
var errNotImplemented = errors.New("not implemented")
|
||||
|
||||
// DummyAddr is a placeholder net.Addr, for when a programming interface
|
||||
// requires a net.Addr but there is none relevant. All DummyAddrs compare equal
|
||||
// to each other.
|
||||
type DummyAddr struct{}
|
||||
|
||||
func (addr DummyAddr) Network() string { return "dummy" }
|
||||
func (addr DummyAddr) String() string { return "dummy" }
|
||||
|
||||
Reference in New Issue
Block a user