Skip to content

Commit

Permalink
Add wireguard outbound
Browse files Browse the repository at this point in the history
  • Loading branch information
nekohasekai committed May 1, 2022
1 parent e7e1b61 commit 8e05a68
Show file tree
Hide file tree
Showing 11 changed files with 1,341 additions and 4 deletions.
14 changes: 14 additions & 0 deletions common/net/destination.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,20 @@ func (d Destination) IsValid() bool {
return d.Network != Network_Unknown
}

func (d Destination) TCPAddr() *net.TCPAddr {
return &net.TCPAddr{
IP: d.Address.IP(),
Port: int(d.Port),
}
}

func (d Destination) UDPAddr() *net.UDPAddr {
return &net.UDPAddr{
IP: d.Address.IP(),
Port: int(d.Port),
}
}

// AsDestination converts current Endpoint into Destination.
func (p *Endpoint) AsDestination() Destination {
return Destination{
Expand Down
13 changes: 11 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,18 @@ require (
golang.org/x/net v0.0.0-20211205041911-012df41ee64c
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
golang.org/x/sys v0.0.0-20211205182925-97ca703d548d
golang.zx2c4.com/wireguard v0.0.0-20211209221555-9c9e7e272434
google.golang.org/grpc v1.42.0
google.golang.org/protobuf v1.27.1
gopkg.in/yaml.v2 v2.4.0
gvisor.dev/gvisor v0.0.0
h12.io/socks v1.0.3
inet.af/netaddr v0.0.0-20211027220019-c74959edd3b6
)

// https://github.com/google/gvisor/releases/tag/release-20220103.0
replace gvisor.dev/gvisor => github.com/google/gvisor v0.0.0-20220101053744-1d5a116c5b1d

require (
github.com/cheekybits/genny v1.0.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
Expand All @@ -42,6 +47,7 @@ require (
github.com/go-playground/locales v0.14.0 // indirect
github.com/go-playground/universal-translator v0.18.0 // indirect
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 // indirect
github.com/google/btree v1.0.1 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/lunixbochs/struc v0.0.0-20200707160740-784aaebc1d40 // indirect
github.com/marten-seemann/qtls-go1-16 v0.1.4 // indirect
Expand All @@ -54,9 +60,12 @@ require (
go4.org/unsafe/assume-no-moving-gc v0.0.0-20211027215541-db492cf91b37 // indirect
golang.org/x/mod v0.4.2 // indirect
golang.org/x/text v0.3.6 // indirect
golang.org/x/tools v0.1.1 // indirect
golang.org/x/time v0.0.0-20191024005414-555d28b269f0 // indirect
golang.org/x/tools v0.1.5 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 // indirect
golang.zx2c4.com/go118/netip v0.0.0-20211111135330-a4a02eeacf9d // indirect
golang.zx2c4.com/wintun v0.0.0-20211104114900-415007cec224 // indirect
google.golang.org/genproto v0.0.0-20210722135532-667f2b7c528f // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)
345 changes: 343 additions & 2 deletions go.sum

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions infra/conf/v4/v2ray.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ var (
"trojan": func() interface{} { return new(TrojanClientConfig) },
"dns": func() interface{} { return new(DNSOutboundConfig) },
"loopback": func() interface{} { return new(LoopbackConfig) },
"wireguard": func() interface{} { return new(WireGuardClientConfig) },
}, "protocol", "settings")
)

Expand Down
34 changes: 34 additions & 0 deletions infra/conf/v4/wireguard.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package v4

import (
"github.com/golang/protobuf/proto"

"github.com/v2fly/v2ray-core/v5/infra/conf/cfgcommon"
"github.com/v2fly/v2ray-core/v5/proxy/wireguard"
)

type WireGuardClientConfig struct {
Address *cfgcommon.Address `json:"address"`
Port uint16 `json:"port"`
Network cfgcommon.Network `json:"network"`
LocalAddresses cfgcommon.StringList `json:"localAddresses"`
PrivateKey string `json:"privateKey"`
PeerPublicKey string `json:"peerPublicKey"`
PreSharedKey string `json:"preSharedKey"`
MTU uint32 `json:"mtu"`
UserLevel uint32 `json:"userLevel"`
}

func (v *WireGuardClientConfig) Build() (proto.Message, error) {
return &wireguard.Config{
Address: v.Address.Build(),
Port: uint32(v.Port),
Network: v.Network.Build(),
LocalAddress: v.LocalAddresses,
PrivateKey: v.PrivateKey,
PeerPublicKey: v.PeerPublicKey,
PreSharedKey: v.PreSharedKey,
Mtu: v.MTU,
UserLevel: v.UserLevel,
}, nil
}
Loading

0 comments on commit 8e05a68

Please sign in to comment.