Skip to content

Commit

Permalink
Merge branch 'make-internal-libs'
Browse files Browse the repository at this point in the history
  • Loading branch information
osm committed Sep 17, 2024
2 parents d8795e3 + 555e7bd commit 01e71a6
Show file tree
Hide file tree
Showing 34 changed files with 90 additions and 769 deletions.
7 changes: 0 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,9 @@ module github.com/mullvad/apisocks5

go 1.22.5

replace github.com/mullvad/ipv6md => ./ipv6md

replace github.com/mullvad/proxy => ./proxy

require github.com/mullvad/proxy v0.0.0-00010101000000-000000000000

require (
github.com/likexian/doh-go v0.6.5 // indirect
github.com/likexian/gokit v0.25.15 // indirect
github.com/mullvad/ipv6md v0.0.0-00010101000000-000000000000 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/text v0.16.0 // indirect
)
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import (
"net"
"net/netip"

"github.com/mullvad/ipv6md"
"github.com/mullvad/ipv6md/utils"
"github.com/mullvad/apisocks5/internal/ipv6md"
"github.com/mullvad/apisocks5/internal/ipv6md/utils"
)

var (
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import (
"net"
"net/netip"

"github.com/mullvad/ipv6md"
"github.com/mullvad/ipv6md/addrport"
"github.com/mullvad/ipv6md/utils"
"github.com/mullvad/apisocks5/internal/ipv6md"
"github.com/mullvad/apisocks5/internal/ipv6md/addrport"
"github.com/mullvad/apisocks5/internal/ipv6md/utils"
)

var (
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import (
"net"
"net/netip"

"github.com/mullvad/ipv6md"
"github.com/mullvad/ipv6md/addrport"
"github.com/mullvad/ipv6md/utils"
"github.com/mullvad/apisocks5/internal/ipv6md"
"github.com/mullvad/apisocks5/internal/ipv6md/addrport"
"github.com/mullvad/apisocks5/internal/ipv6md/utils"
)

var (
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
40 changes: 40 additions & 0 deletions internal/proxy/plain/plain.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package plain

import (
"io"
"net"

"github.com/mullvad/apisocks5/internal/ipv6md/addrport"
"github.com/mullvad/apisocks5/internal/proxy/typ"
)

type Plain struct {
addrPort string
}

func New(ip net.IP) (*Plain, error) {
target, err := addrport.Decode(ip)
if err != nil {
return nil, err
}

return &Plain{
addrPort: target.String(),
}, nil
}

func (p *Plain) Address() string { return p.addrPort }
func (p *Plain) Type() typ.Type { return typ.Plain }
func (p *Plain) FromPeer(dst io.Writer, src io.Reader) { p.forward(dst, src) }
func (p *Plain) ToPeer(dst io.Writer, src io.Reader) { p.forward(dst, src) }

func (p *Plain) forward(dst io.Writer, src io.Reader) {
io.Copy(dst, src)

tcpConn, ok := dst.(*net.TCPConn)
if !ok {
return
}

tcpConn.CloseWrite()
}
2 changes: 1 addition & 1 deletion proxy/proxy.go → internal/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package proxy
import (
"io"

"github.com/mullvad/proxy/typ"
"github.com/mullvad/apisocks5/internal/proxy/typ"
)

type Proxy interface {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import (

"github.com/likexian/doh-go"
"github.com/likexian/doh-go/dns"
"github.com/mullvad/ipv6md"
"github.com/mullvad/apisocks5/internal/ipv6md"

"github.com/mullvad/proxy/plain"
"github.com/mullvad/proxy/xor"
"github.com/mullvad/proxy/xorv2"
"github.com/mullvad/apisocks5/internal/proxy/plain"
"github.com/mullvad/apisocks5/internal/proxy/xor"
"github.com/mullvad/apisocks5/internal/proxy/xorv2"
)

func Query(domains []string, verbose bool) []Proxy {
Expand Down
File renamed without changes.
20 changes: 10 additions & 10 deletions proxy/xor/xor.go → internal/proxy/xor/xor.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,35 @@ import (
"io"
"net"

"github.com/mullvad/ipv6md/addrportxor"
"github.com/mullvad/proxy/typ"
"github.com/mullvad/apisocks5/internal/ipv6md/addrportxor"
"github.com/mullvad/apisocks5/internal/proxy/typ"
)

type xor struct {
type XOR struct {
addrPort string
xorBytes uint16
xorKey []byte
}

func New(ip net.IP) (*xor, error) {
func New(ip net.IP) (*XOR, error) {
target, err := addrportxor.Decode(ip)
if err != nil {
return nil, err
}

return &xor{
return &XOR{
addrPort: target.AddrPort.String(),
xorBytes: target.XORBytes,
xorKey: target.XORKey,
}, nil
}

func (x *xor) Address() string { return x.addrPort }
func (x *xor) Type() typ.Type { return typ.XOR }
func (x *xor) FromPeer(dst io.Writer, src io.Reader) { x.forward(dst, src) }
func (x *xor) ToPeer(dst io.Writer, src io.Reader) { x.forward(dst, src) }
func (x *XOR) Address() string { return x.addrPort }
func (x *XOR) Type() typ.Type { return typ.XOR }
func (x *XOR) FromPeer(dst io.Writer, src io.Reader) { x.forward(dst, src) }
func (x *XOR) ToPeer(dst io.Writer, src io.Reader) { x.forward(dst, src) }

func (x *xor) forward(dst io.Writer, src io.Reader) {
func (x *XOR) forward(dst io.Writer, src io.Reader) {
buf := make([]byte, 1024*64)

for {
Expand Down
20 changes: 10 additions & 10 deletions proxy/xorv2/xorv2.go → internal/proxy/xorv2/xorv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,33 @@ import (
"io"
"net"

"github.com/mullvad/ipv6md/addrportxorv2"
"github.com/mullvad/proxy/typ"
"github.com/mullvad/apisocks5/internal/ipv6md/addrportxorv2"
"github.com/mullvad/apisocks5/internal/proxy/typ"
)

type xor struct {
type XORV2 struct {
addrPort string
xorKey []byte
}

func New(ip net.IP) (*xor, error) {
func New(ip net.IP) (*XORV2, error) {
target, err := addrportxorv2.Decode(ip)
if err != nil {
return nil, err
}

return &xor{
return &XORV2{
addrPort: target.AddrPort.String(),
xorKey: target.XORKey,
}, nil
}

func (x *xor) Address() string { return x.addrPort }
func (x *xor) Type() typ.Type { return typ.XORV2 }
func (x *xor) FromPeer(dst io.Writer, src io.Reader) { x.forward(dst, src) }
func (x *xor) ToPeer(dst io.Writer, src io.Reader) { x.forward(dst, src) }
func (x *XORV2) Address() string { return x.addrPort }
func (x *XORV2) Type() typ.Type { return typ.XORV2 }
func (x *XORV2) FromPeer(dst io.Writer, src io.Reader) { x.forward(dst, src) }
func (x *XORV2) ToPeer(dst io.Writer, src io.Reader) { x.forward(dst, src) }

func (x *xor) forward(dst io.Writer, src io.Reader) {
func (x *XORV2) forward(dst io.Writer, src io.Reader) {
buf := make([]byte, 1024*64)
offset := 0

Expand Down
20 changes: 14 additions & 6 deletions proxy/xorv2/xorv2_test.go → internal/proxy/xorv2/xorv2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package xorv2

import (
"bytes"
"io"
"net"
"strings"
"testing"
"time"
)

// TestToPeer tests the ToPeer method of the xorv2 proxy. It specifically
Expand All @@ -16,13 +17,20 @@ func TestToPeer(t *testing.T) {
t.Errorf("unable to create new XOR proxy: %v", err)
}

var dst1 bytes.Buffer
xor.ToPeer(&dst1, strings.NewReader("foo bar baz"))
pr, pw := io.Pipe()
var dst bytes.Buffer

var dst2 bytes.Buffer
xor.ToPeer(&dst2, strings.NewReader("foo bar baz"))
go func() {
pw.Write([]byte("foo bar baz"))
time.Sleep(10 * time.Millisecond)
pw.Write([]byte("foo bar baz"))
pw.Close()
}()

if bytes.Equal(dst1.Bytes(), dst2.Bytes()) {
xor.ToPeer(&dst, pr)
data := dst.Bytes()

if bytes.Equal(data[:11], data[11:]) {
t.Errorf("XOR:ed data is equal")
}
}
100 changes: 0 additions & 100 deletions ipv6md/addrportxor/addrportxor.go

This file was deleted.

3 changes: 0 additions & 3 deletions ipv6md/go.mod

This file was deleted.

4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"runtime"
"strings"

"github.com/mullvad/proxy"
"github.com/mullvad/proxy/typ"
"github.com/mullvad/apisocks5/internal/proxy"
"github.com/mullvad/apisocks5/internal/proxy/typ"
)

var appVersion string
Expand Down
16 changes: 0 additions & 16 deletions proxy/go.mod

This file was deleted.

12 changes: 0 additions & 12 deletions proxy/go.sum

This file was deleted.

Loading

0 comments on commit 01e71a6

Please sign in to comment.