Skip to content

Commit

Permalink
chore: move some packages to pkg folder
Browse files Browse the repository at this point in the history
  • Loading branch information
nadoo committed Jan 8, 2022
1 parent a529261 commit 1fd59a1
Show file tree
Hide file tree
Showing 82 changed files with 133 additions and 123 deletions.
5 changes: 3 additions & 2 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ builds:
env:
- CGO_ENABLED=0
# GOOS list to build for.
# For more info refer to: https://golang.org/doc/install/source#environment
# For more info refer to: https://go.dev/doc/install/source#environment
# Defaults are darwin and linux.
goos:
- windows
Expand All @@ -39,6 +39,7 @@ builds:
- mipsle
- mips64
- mips64le
- riscv64
goarm:
- 6
- 7
Expand All @@ -53,7 +54,7 @@ archives:
- default
name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if .Mips }}_{{ .Mips }}{{ end }}"
replacements:
darwin: mac
darwin: macos
wrap_in_directory: true
format: tar.gz
format_overrides:
Expand Down
2 changes: 1 addition & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/nadoo/conflag"

"github.com/nadoo/glider/dns"
"github.com/nadoo/glider/log"
"github.com/nadoo/glider/pkg/log"
"github.com/nadoo/glider/proxy"
"github.com/nadoo/glider/rule"
)
Expand Down
4 changes: 2 additions & 2 deletions dns/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"strings"
"time"

"github.com/nadoo/glider/log"
"github.com/nadoo/glider/pool"
"github.com/nadoo/glider/pkg/log"
"github.com/nadoo/glider/pkg/pool"
"github.com/nadoo/glider/proxy"
)

Expand Down
4 changes: 2 additions & 2 deletions dns/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"sync"
"time"

"github.com/nadoo/glider/log"
"github.com/nadoo/glider/pool"
"github.com/nadoo/glider/pkg/log"
"github.com/nadoo/glider/pkg/pool"
"github.com/nadoo/glider/proxy"
)

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ require (
github.com/templexxx/xorsimd v0.4.1 // indirect
github.com/tjfoc/gmsm v1.4.1 // indirect
github.com/u-root/uio v0.0.0-20210528151154-e40b768296a7 // indirect
golang.org/x/net v0.0.0-20211216030914-fe4d6282115f // indirect
golang.org/x/net v0.0.0-20220107192237-5cfca573fb4d // indirect
)

// Replace dependency modules with local developing copy
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81R
golang.org/x/net v0.0.0-20201010224723-4f7140c49acb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211216030914-fe4d6282115f h1:hEYJvxw1lSnWIl8X9ofsYMklzaDs90JI2az5YMd4fPM=
golang.org/x/net v0.0.0-20211216030914-fe4d6282115f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220107192237-5cfca573fb4d h1:62NvYBuaanGXR2ZOfwDFkhhl6X1DUgf8qg3GuQvxZsE=
golang.org/x/net v0.0.0-20220107192237-5cfca573fb4d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

"github.com/nadoo/glider/dns"
"github.com/nadoo/glider/ipset"
"github.com/nadoo/glider/log"
"github.com/nadoo/glider/pkg/log"
"github.com/nadoo/glider/proxy"
"github.com/nadoo/glider/rule"
"github.com/nadoo/glider/service"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion proxy/protocol/smux/session.go → pkg/smux/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"sync/atomic"
"time"

"github.com/nadoo/glider/pool"
"github.com/nadoo/glider/pkg/pool"
)

const (
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion proxy/protocol/smux/stream.go → pkg/smux/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"sync/atomic"
"time"

"github.com/nadoo/glider/pool"
"github.com/nadoo/glider/pkg/pool"
)

// Stream implements net.Conn
Expand Down
16 changes: 16 additions & 0 deletions pkg/sockopt/bind_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package sockopt

import (
"net"
"syscall"

"golang.org/x/sys/unix"
)

func BindControl(iface *net.Interface) func(network, address string, c syscall.RawConn) error {
return func(network, address string, c syscall.RawConn) error {
return c.Control(func(fd uintptr) {
unix.BindToDevice(int(fd), iface.Name)
})
}
}
11 changes: 11 additions & 0 deletions pkg/sockopt/bind_others.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//go:build !linux
// +build !linux

package sockopt

import (
"net"
"syscall"
)

func BindControl(iface *net.Interface) func(string, string, syscall.RawConn) error { return nil }
File renamed without changes.
14 changes: 0 additions & 14 deletions proxy/bind_linux.go

This file was deleted.

8 changes: 0 additions & 8 deletions proxy/bind_others.go

This file was deleted.

2 changes: 1 addition & 1 deletion proxy/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"sync"
"time"

"github.com/nadoo/glider/pool"
"github.com/nadoo/glider/pkg/pool"
)

var (
Expand Down
14 changes: 10 additions & 4 deletions proxy/direct.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package proxy

import (
"context"
"errors"
"net"
"time"

"github.com/nadoo/glider/log"
"github.com/nadoo/glider/pkg/log"
"github.com/nadoo/glider/pkg/sockopt"
)

// Direct proxy.
Expand Down Expand Up @@ -86,7 +88,7 @@ func (d *Direct) dial(network, addr string, localIP net.IP) (net.Conn, error) {

dialer := &net.Dialer{LocalAddr: la, Timeout: d.dialTimeout}
if d.iface != nil {
bind(dialer, d.iface)
dialer.Control = sockopt.BindControl(d.iface)
}

c, err := dialer.Dial(network, addr)
Expand All @@ -107,13 +109,17 @@ func (d *Direct) dial(network, addr string, localIP net.IP) (net.Conn, error) {

// DialUDP connects to the given address.
func (d *Direct) DialUDP(network, addr string) (net.PacketConn, net.Addr, error) {
// TODO: support specifying local interface
var la string
if d.ip != nil {
la = net.JoinHostPort(d.ip.String(), "0")
}

pc, err := net.ListenPacket(network, la)
lc := &net.ListenConfig{}
if d.iface != nil {
lc.Control = sockopt.BindControl(d.iface)
}

pc, err := lc.ListenPacket(context.Background(), network, la)
if err != nil {
log.F("ListenPacket error: %s", err)
return nil, nil, err
Expand Down
4 changes: 2 additions & 2 deletions proxy/http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"net"
"net/textproto"

"github.com/nadoo/glider/log"
"github.com/nadoo/glider/pool"
"github.com/nadoo/glider/pkg/log"
"github.com/nadoo/glider/pkg/pool"
"github.com/nadoo/glider/proxy"
)

Expand Down
2 changes: 1 addition & 1 deletion proxy/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"net/url"
"strings"

"github.com/nadoo/glider/log"
"github.com/nadoo/glider/pkg/log"
"github.com/nadoo/glider/proxy"
)

Expand Down
2 changes: 1 addition & 1 deletion proxy/http/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"net/url"
"strings"

"github.com/nadoo/glider/log"
"github.com/nadoo/glider/pkg/log"
)

// Methods are http methods from rfc.
Expand Down
4 changes: 2 additions & 2 deletions proxy/http/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"strings"
"time"

"github.com/nadoo/glider/log"
"github.com/nadoo/glider/pool"
"github.com/nadoo/glider/pkg/log"
"github.com/nadoo/glider/pkg/pool"
"github.com/nadoo/glider/proxy"
)

Expand Down
2 changes: 1 addition & 1 deletion proxy/kcp/kcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
kcp "github.com/xtaci/kcp-go/v5"
"golang.org/x/crypto/pbkdf2"

"github.com/nadoo/glider/log"
"github.com/nadoo/glider/pkg/log"
"github.com/nadoo/glider/proxy"
)

Expand Down
2 changes: 1 addition & 1 deletion proxy/mixed/mixed.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"net"
"net/url"

"github.com/nadoo/glider/log"
"github.com/nadoo/glider/pkg/log"
"github.com/nadoo/glider/proxy"
"github.com/nadoo/glider/proxy/http"
"github.com/nadoo/glider/proxy/socks5"
Expand Down
2 changes: 1 addition & 1 deletion proxy/obfs/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"io"
"net"

"github.com/nadoo/glider/pool"
"github.com/nadoo/glider/pkg/pool"
)

// HTTPObfs struct
Expand Down
2 changes: 1 addition & 1 deletion proxy/obfs/obfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"net"
"net/url"

"github.com/nadoo/glider/log"
"github.com/nadoo/glider/pkg/log"
"github.com/nadoo/glider/proxy"
)

Expand Down
2 changes: 1 addition & 1 deletion proxy/obfs/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"net"
"time"

"github.com/nadoo/glider/pool"
"github.com/nadoo/glider/pkg/pool"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion proxy/pxyproto/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"net/url"
"strings"

"github.com/nadoo/glider/log"
"github.com/nadoo/glider/pkg/log"
"github.com/nadoo/glider/proxy"
)

Expand Down
2 changes: 1 addition & 1 deletion proxy/redir/redir_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"syscall"
"unsafe"

"github.com/nadoo/glider/log"
"github.com/nadoo/glider/pkg/log"
"github.com/nadoo/glider/proxy"
)

Expand Down
5 changes: 2 additions & 3 deletions proxy/smux/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import (
"net/url"
"sync"

"github.com/nadoo/glider/log"
"github.com/nadoo/glider/pkg/log"
"github.com/nadoo/glider/pkg/smux"
"github.com/nadoo/glider/proxy"

"github.com/nadoo/glider/proxy/protocol/smux"
)

// SmuxClient struct.
Expand Down
5 changes: 2 additions & 3 deletions proxy/smux/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import (
"net/url"
"strings"

"github.com/nadoo/glider/log"
"github.com/nadoo/glider/pkg/log"
"github.com/nadoo/glider/pkg/smux"
"github.com/nadoo/glider/proxy"

"github.com/nadoo/glider/proxy/protocol/smux"
)

// SmuxServer struct.
Expand Down
4 changes: 2 additions & 2 deletions proxy/socks4/socks4.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"net/url"
"strconv"

"github.com/nadoo/glider/log"
"github.com/nadoo/glider/pool"
"github.com/nadoo/glider/pkg/log"
"github.com/nadoo/glider/pkg/pool"
"github.com/nadoo/glider/proxy"
)

Expand Down
6 changes: 3 additions & 3 deletions proxy/socks5/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (
"net"
"strconv"

"github.com/nadoo/glider/log"
"github.com/nadoo/glider/pool"
"github.com/nadoo/glider/pkg/log"
"github.com/nadoo/glider/pkg/pool"
"github.com/nadoo/glider/pkg/socks"
"github.com/nadoo/glider/proxy"
"github.com/nadoo/glider/proxy/protocol/socks"
)

// NewSocks5Dialer returns a socks5 proxy dialer.
Expand Down
4 changes: 2 additions & 2 deletions proxy/socks5/packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"errors"
"net"

"github.com/nadoo/glider/pool"
"github.com/nadoo/glider/proxy/protocol/socks"
"github.com/nadoo/glider/pkg/pool"
"github.com/nadoo/glider/pkg/socks"
)

// PktConn .
Expand Down
6 changes: 3 additions & 3 deletions proxy/socks5/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
"sync"
"time"

"github.com/nadoo/glider/log"
"github.com/nadoo/glider/pool"
"github.com/nadoo/glider/pkg/log"
"github.com/nadoo/glider/pkg/pool"
"github.com/nadoo/glider/pkg/socks"
"github.com/nadoo/glider/proxy"
"github.com/nadoo/glider/proxy/protocol/socks"
)

var nm sync.Map
Expand Down
2 changes: 1 addition & 1 deletion proxy/socks5/socks5.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ package socks5
import (
"net/url"

"github.com/nadoo/glider/log"
"github.com/nadoo/glider/pkg/log"
"github.com/nadoo/glider/proxy"
)

Expand Down
Loading

0 comments on commit 1fd59a1

Please sign in to comment.