Compare commits

..

115 Commits

Author SHA1 Message Date
Darien Raymond
9ad96949b0 Update version 2016-09-19 11:23:03 +02:00
Darien Raymond
8b37edd02d format log 2016-09-18 00:46:16 +02:00
Darien Raymond
d08cba000f accounts in protobuf 2016-09-18 00:41:21 +02:00
Darien Raymond
3423adaea4 fix test break 2016-08-29 12:25:16 +02:00
Darien Raymond
7a31e7a0c2 fix test break 2016-08-29 12:23:17 +02:00
Darien Raymond
7f2ba0d106 remove unnecessary code 2016-08-28 23:47:39 +02:00
Darien Raymond
948f04921d update socks code for server config 2016-08-28 23:46:50 +02:00
Darien Raymond
ea2c491ade global proto gen 2016-08-28 23:41:51 +02:00
Darien Raymond
11e310298c proto for socks server 2016-08-28 23:41:45 +02:00
Darien Raymond
0f74c618de close input stream early 2016-08-28 12:01:37 +02:00
Darien Raymond
9b72d3cbd7 simplify socks transport 2016-08-28 11:59:03 +02:00
Darien Raymond
bd4ca7b37f remote protobuf code from coverage 2016-08-27 12:00:51 +02:00
Darien Raymond
cdb4c56546 protobuf for net 2016-08-27 00:04:35 +02:00
Darien Raymond
64e38ba851 update chinaip 2016-08-25 22:17:57 +02:00
Darien Raymond
bbca180dba try protobuf 2016-08-25 21:55:49 +02:00
Darien Raymond
04d956462c fix test without -json tag 2016-08-25 13:25:59 +02:00
Darien Raymond
3fd66ad795 remove PingNecessary() 2016-08-25 12:00:31 +02:00
Darien Raymond
e49fb2f50d no compacting buffers 2016-08-25 11:41:05 +02:00
Darien Raymond
59125f665b allow env speicified buffer size 2016-08-25 11:21:32 +02:00
Darien Raymond
fcad4aa212 adjust receiving buffer size 2016-08-25 09:45:56 +02:00
Darien Raymond
0da987ec43 refine buffer size 2016-08-25 00:04:54 +02:00
Darien Raymond
2ae8e5d033 rename buffer size 2016-08-24 23:54:39 +02:00
Darien Raymond
2839ce7a88 simplify receiving worker 2016-08-24 23:51:53 +02:00
Darien Raymond
5d20e3f70b remove sending queue 2016-08-24 15:47:14 +02:00
Darien Raymond
e6e0419958 format private annotation 2016-08-24 11:17:42 +02:00
Darien Raymond
a9da266bf9 update default in-fligh size 2016-08-24 07:50:33 +02:00
Darien Raymond
98025e1457 change default kcp.tti to 50 2016-08-23 23:32:36 +02:00
Darien Raymond
85c5171d8d update deploy key 2016-08-22 23:09:25 +02:00
Darien Raymond
e7bf0c2e49 fix install script 2016-08-21 18:02:12 +02:00
Darien Raymond
8eab746c96 doc 2016-08-21 09:06:15 +02:00
Darien Raymond
fdeb8b4f89 update file paths 2016-08-20 21:03:50 +02:00
v2ray
07a86f549b unified import path 2016-08-20 20:55:45 +02:00
v2ray
6a878432dc Update version 2016-08-20 20:40:24 +02:00
v2ray
d08ffedf48 reduce ping frequency 2016-08-20 11:33:22 +02:00
v2ray
0a34ec0be6 prepare for 2.0 2016-08-20 09:37:08 +02:00
v2ray
7a1bdfcf00 test case for passive connection 2016-08-20 09:12:44 +02:00
v2ray
2268f3d1bc remove import path restriction 2016-08-19 17:05:15 +02:00
v2ray
d83a0ce5d2 Apply new read function to UDP hub. 2016-08-19 13:00:55 +02:00
v2ray
55e5268ce8 Fix UDP reading on Windows 2016-08-19 12:58:26 +02:00
v2ray
ad1353ac2f merge similar error definitions 2016-08-18 08:34:21 +02:00
v2ray
786775ea80 fix build break 2016-08-18 08:24:47 +02:00
v2ray
39737f6fc1 merge bad configuration error 2016-08-18 08:21:20 +02:00
v2ray
933e244d92 value receiver for StringList.Len() 2016-08-18 07:56:31 +02:00
v2ray
89a876a6d4 rename proxy/internal to proxy/registry 2016-08-17 23:30:15 +02:00
v2ray
d9884b4010 format import 2016-08-17 23:14:13 +02:00
v2ray
8ecec9b49d format log 2016-08-17 23:12:10 +02:00
v2ray
bb3ceb3d7b simplify case 2016-08-17 23:05:47 +02:00
v2ray
49056d9942 Merge branch 'master' of https://github.com/v2ray/v2ray-core 2016-08-17 15:25:40 +02:00
Darien Raymond
8951c4da71 comment 2016-08-17 10:05:53 +00:00
v2ray
99a63f1633 reset timer before benchmark 2016-08-17 10:28:30 +02:00
v2ray
99821dc2fb change to wait group 2016-08-16 17:00:04 +02:00
v2ray
125ef8372c actually follow redirect of UDP 2016-08-16 13:04:07 +02:00
v2ray
41d89e6d1e skip test requires root permission 2016-08-16 09:01:58 +02:00
v2ray
9876844296 fix test break 2016-08-16 08:37:38 +02:00
v2ray
a83009afc4 update to 1.7 2016-08-16 08:37:18 +02:00
v2ray
7bc94d55c6 need sudo permission 2016-08-15 23:11:48 +02:00
v2ray
6417adb56d correctly get sys fd from udp conn 2016-08-15 23:11:01 +02:00
v2ray
d025b8d48f fix test break 2016-08-15 23:02:03 +02:00
v2ray
0bca6e8657 fix kcp listener 2016-08-15 22:20:16 +02:00
v2ray
a5a70afdb8 remove port testing 2016-08-15 22:12:11 +02:00
v2ray
338dc1ebb6 remove unused deps 2016-08-15 21:51:51 +02:00
v2ray
c7871a3ab2 test case for socket opt 2016-08-15 21:33:32 +02:00
v2ray
2a778762b1 rename udp.go to hub.go 2016-08-15 21:33:21 +02:00
Darien Raymond
667b71aad0 Merge pull request #238 from xiaokangwang/websocket
Websocket transport support for v2ray
2016-08-15 17:45:25 +02:00
v2ray
210a32dc12 support udp redirection 2016-08-15 17:44:46 +02:00
Shelikhoo
22519353c3 Check Read 2016-08-15 21:55:43 +08:00
Shelikhoo
32e8deb6e8 Simplify Design 2016-08-15 21:36:37 +08:00
Shelikhoo
45d801b922 WsTest:more case 2016-08-15 21:29:15 +08:00
Shelikhoo
6c8b4f5db3 Fix 2016-08-15 21:21:09 +08:00
Shelikhoo
d7440bb1d6 Test:listen tls 2016-08-15 21:19:53 +08:00
Shelikhoo
856f2a2dd3 Fix assert fail 2016-08-15 21:19:15 +08:00
Shelikhoo
4b9e506dba Added Testing Cert 2016-08-15 21:18:48 +08:00
Shelikhoo
f7ce9d3be6 Add Developer Insecure Skip Verify for testing 2016-08-15 20:42:38 +08:00
v2ray
956b47f6ae release connection after all data read in freedom 2016-08-15 14:31:46 +02:00
Shelikhoo
02e3c17c97 test:listen 2016-08-15 20:20:47 +08:00
Shelikhoo
40ec84e222 Dial test 2016-08-15 20:15:12 +08:00
Shelikhoo
2209294dfc Set reuse limit 2016-08-15 20:14:45 +08:00
Shelikhoo
0a49628555 Bettering ping method 2016-08-15 19:13:18 +08:00
Shelikhoo
e382eaa59f typo 2016-08-15 18:59:50 +08:00
Shelikhoo
4c093a2107 Apply coding style 2016-08-15 18:59:14 +08:00
Shelikhoo
a5ae6a0f4e Remove workaround 2016-08-15 18:57:39 +08:00
Shelikhoo
bfb4e0d9b0 Apply coding style 2016-08-15 18:56:33 +08:00
Shelikhoo
273c8f6c57 Support Stop listener 2016-08-15 18:47:44 +08:00
Shelikhoo
062d05fdcf Added Stoppable listener for TLS listener 2016-08-15 18:43:17 +08:00
v2ray
66bb7879e0 handle empty payload in freedom and outbound 2016-08-15 12:23:35 +02:00
Shelikhoo
c8cd1320c7 Use stopable listener for HTTP 2016-08-15 18:17:29 +08:00
Shelikhoo
a36582b294 Added stopable listener 2016-08-15 18:16:54 +08:00
Shelikhoo
863237b518 Justify lock use 2016-08-15 17:53:11 +08:00
Shelikhoo
4853a1a6d3 Increase ping time 2016-08-15 17:48:30 +08:00
Shelikhoo
de28198234 Guess protocol 2016-08-15 17:47:15 +08:00
Shelikhoo
7b3cf631c2 Removed inaccessable doc 2016-08-15 17:40:56 +08:00
Shelikhoo
ee22082fb4 Fix host bug 2016-08-15 14:30:38 +08:00
Shelikhoo
00aeb29e46 typo 2016-08-15 12:31:55 +08:00
Shelikhoo
2bf9edfe7d Prevent unnesessary log 2016-08-15 12:23:15 +08:00
Shelikhoo
d250013c99 Increase conn keep-alive time 2016-08-15 11:07:29 +08:00
Shelikhoo
d06c75f926 Doc sync to code change 2016-08-15 10:25:20 +08:00
Shelikhoo
7259b3363b Merge branch 'master' into websockwt 2016-08-15 10:17:22 +08:00
Shelikhoo
fed2933043 fix crash 2016-08-14 20:41:26 +08:00
Shelikhoo
5e576e11bb fix crash 2016-08-14 20:40:59 +08:00
Shelikhoo
49441a5050 Docs 2016-08-14 14:11:51 +08:00
Shelikhoo
a0fda39274 Fix crash 2016-08-14 11:06:39 +08:00
Shelikhoo
3e9e9b520e Remove useless test 2016-08-14 09:23:24 +08:00
Shelikhoo
1fe090dbfd Verfiy Domain correctly 2016-08-13 22:50:24 +08:00
Shelikhoo
427bed5ddb typo~ 2016-08-13 22:07:47 +08:00
Shelikhoo
16b529093d Support Listen WebSocket with TLS 2016-08-13 21:56:51 +08:00
Shelikhoo
fecf9cc5b8 Added WebSocket transport 2016-08-13 21:44:36 +08:00
Shelikhoo
7ef66c57dc Support Listen WebSocket Connection 2016-08-13 21:43:46 +08:00
Shelikhoo
29f69d63c4 Support Dial WebSocket Connection 2016-08-13 21:42:56 +08:00
Shelikhoo
20f16309e6 Load Websocket Streamtype from json 2016-08-13 21:42:18 +08:00
Shelikhoo
0d60d2449a Add Websocket Stream type 2016-08-13 21:41:13 +08:00
Shelikhoo
2eced2bd6c Load Configure from json 2016-08-13 21:39:34 +08:00
Shelikhoo
8c4a6d94f9 WS Conf structure 2016-08-13 21:37:17 +08:00
Shelikhoo
8c96b1961b load ws transport on init 2016-08-13 21:35:31 +08:00
Shelikhoo
508f79f95f Advertise WS cap 2016-08-13 21:33:34 +08:00
Shelikhoo
cb1356be75 Register ws network 2016-08-13 21:32:47 +08:00
303 changed files with 11484 additions and 9220 deletions

View File

@@ -1,14 +1,16 @@
language: go
go:
- 1.6.3
- 1.7
go_import_path: v2ray.com/core
git:
depth: 5
script:
- go test -tags json github.com/v2ray/v2ray-core/...
- go test -tags json v2ray.com/core/...
after_success:
- ./testing/coverage/coverall
@@ -19,7 +21,7 @@ before_deploy:
deploy:
provider: releases
api_key:
secure: "Nbno1ibFpq0DC6y0mkN6NFTbDQinRAEQo2Jl5lvsbiaX9m4CK59xG8XOcmZ3mqqdeioj6m9X5BVe2UtCZjmXmnyPq0FYNFHAPTfd2VrcOpi0fWLD9ndTYAsqjxrqPGK62XVjPbG8U2pGdq2yCOb0qQ9DlahDhVIMzQ/GYuRDps25fPGftepdPwlrwOfYCIvAHoi3GEozuS67WNEx/YtmZTce/2Qebdmwf44hUNaQibeXEspu9wQcp9M/i7aTuX/tUbn7rVCQ4TfoIJU1C1qKedUw0QYMjqP08Wn6UjwwhbblsJKFv8Kc0nx+i2K9CvvLyaBBIVY2Ggxj4Niy+X4VbyWWzdKx+0FXlmKh3U/hJdMZU3OrnwliBns2X3tCHSq7/+7ynLs3UZ4wCkCl7rQYucJ2mlvGquohQV6MX2vjl73y+pYljf+PKYbSDBb7iUOjllisRD+HmDmGQl81BvdEpN/K/BlfsTwHoHxsALSTjRljSngH51SUvjnaVbi/JolJ3lomTr1vCHl4WUiQVLnh7O2Cg7QLNMNieoblnh9yDQG9wC4xuzOJ/AaxRd/pRZMeIooQ1zsHOe+47C1YAep88b+9xtRqVMozAjk/XgNzWjuT2R8G7lZDq0mL9VajD/NUjM3Yrswoft9A3DRmR+lIFJR+fJb8tNf+k1OczE4lesg="
secure: "FORkI+hXFWSxLkqkBDvo8APQ1XLfuzbOBqhVW474x299AzHpgE/7dYLNo/rQaerYMdmw8gB21tUWOI3FjUYv51x1dO2a2Bu8Por+1BQ+zdUIyS3zJteJ8bAMZGVtg1BCTFjxQsIDMmaziaScSKz3NwEJ1IL8UIBiidFf8EuYyK+EL6yQFodrSeUDsUH52pBO0SBugsAj4lOSTCS25ZcpWYcUMBo7zaD9sNE1Oo8f/bz7cFe4cJLCpazIgkt57IT3u/8BH/EMz4HRbAqj48mjKytp4lm7R3IC8w0ba6yLNXgKqva10B/KNwZQweXqglM5iawQDdSbnIjUnVEe9Oexu8wNV52oBt+8wC7P/ZtAsZTnyWvwIhH2uyhzEHfsM5Up7DnAnaATh/+2upn3lcs4s2p9d/6tIObeIpBvP/3QRNmlmtZFIOnlqkcROj9NQ3IHGbswGiAfBDAsAC8h9CRDy9MtRs6ZbaCih0FLgMzEXi+S50eelNRv4SGaeLlW07cz7uma5C+z+zWb4ZmWsOwWjkOAaFL/zL5O9/w7i4cbXr/sQ6z6YmdDEejbrkHiE8DmKQqeV13xY1FhDqFyEpsdUbftG6pKPt5wcyNEAnw9aPMK7Ec0dAe6vg+oTcfMPAO/rHRXEc4IP56QqdlZTmsZOdDrGgnkRxpbayc+KcvrN28="
file:
- "$GOPATH/bin/v2ray-macos.zip"
- "$GOPATH/bin/v2ray-windows-64.zip"

View File

@@ -2,5 +2,12 @@
{
"editor.tabSize": 2,
"go.buildTags": "json"
"go.buildTags": "json",
"protoc": {
"options": [
"--proto_path=$GOPATH/src/",
"--proto_path=$GOPATH/src/github.com/google/protobuf/src"
]
}
}

4
.vscode/tasks.json vendored
View File

@@ -6,7 +6,7 @@
"tasks": [
{
"taskName": "build",
"args": ["-tags", "json", "github.com/v2ray/v2ray-core/..."],
"args": ["-tags", "json", "v2ray.com/core/..."],
"isBuildCommand": true,
"problemMatcher": {
"owner": "go",
@@ -21,7 +21,7 @@
},
{
"taskName": "test",
"args": ["-tags", "json", "github.com/v2ray/v2ray-core/..."],
"args": ["-tags", "json", "v2ray.com/core/..."],
"isBuildCommand": false
}
]

View File

@@ -5,10 +5,10 @@
[2]: https://travis-ci.org/v2ray/v2ray-core "Travis-CI Build Status"
[3]: https://codecov.io/github/v2ray/v2ray-core/coverage.svg?branch=master "Coverage badge"
[4]: https://codecov.io/github/v2ray/v2ray-core?branch=master "Codecov Status"
[5]: https://goreportcard.com/badge/github.com/v2ray/v2ray-core "Go Report badge"
[6]: https://goreportcard.com/report/github.com/v2ray/v2ray-core "Go Report"
[7]: https://godoc.org/github.com/v2ray/v2ray-core?status.svg "GoDoc badge"
[8]: https://godoc.org/github.com/v2ray/v2ray-core "GoDoc"
[5]: https://goreportcard.com/badge/v2ray.com/core "Go Report badge"
[6]: https://goreportcard.com/report/v2ray.com/core "Go Report"
[7]: https://godoc.org/v2ray.com/core?status.svg "GoDoc badge"
[8]: https://godoc.org/v2ray.com/core "GoDoc"
[9]: https://codebeat.co/badges/f2354ca8-3e24-463d-a2e3-159af73b2477 "Codebeat badge"
[10]: https://codebeat.co/projects/github-com-v2ray-v2ray-core "Codebeat"

View File

@@ -1,7 +1,7 @@
package api
import (
"github.com/v2ray/v2ray-core/app"
"v2ray.com/core/app"
)
const (

View File

@@ -1,7 +1,7 @@
package api
import (
v2net "github.com/v2ray/v2ray-core/common/net"
v2net "v2ray.com/core/common/net"
)
type Config struct {

View File

@@ -1,9 +1,9 @@
package dispatcher
import (
"github.com/v2ray/v2ray-core/app"
"github.com/v2ray/v2ray-core/proxy"
"github.com/v2ray/v2ray-core/transport/ray"
"v2ray.com/core/app"
"v2ray.com/core/proxy"
"v2ray.com/core/transport/ray"
)
const (

View File

@@ -1,14 +1,14 @@
package impl
import (
"github.com/v2ray/v2ray-core/app"
"github.com/v2ray/v2ray-core/app/proxyman"
"github.com/v2ray/v2ray-core/app/router"
"github.com/v2ray/v2ray-core/common/alloc"
"github.com/v2ray/v2ray-core/common/log"
v2net "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/proxy"
"github.com/v2ray/v2ray-core/transport/ray"
"v2ray.com/core/app"
"v2ray.com/core/app/proxyman"
"v2ray.com/core/app/router"
"v2ray.com/core/common/alloc"
"v2ray.com/core/common/log"
v2net "v2ray.com/core/common/net"
"v2ray.com/core/proxy"
"v2ray.com/core/transport/ray"
)
type DefaultDispatcher struct {
@@ -24,7 +24,7 @@ func NewDefaultDispatcher(space app.Space) *DefaultDispatcher {
return d
}
// @Private
// Private: Used by app.Space only.
func (this *DefaultDispatcher) Initialize(space app.Space) error {
if !space.HasApp(proxyman.APP_ID_OUTBOUND_MANAGER) {
log.Error("DefaultDispatcher: OutboundHandlerManager is not found in the space.")
@@ -70,7 +70,7 @@ func (this *DefaultDispatcher) DispatchToOutbound(meta *proxy.InboundHandlerMeta
return direct
}
// @Private
// Private: Visible for testing.
func (this *DefaultDispatcher) FilterPacketAndDispatch(destination v2net.Destination, link ray.OutboundRay, dispatcher proxy.OutboundHandler) {
payload, err := link.OutboundInput().Read()
if err != nil {

View File

@@ -1,9 +1,9 @@
package testing
import (
v2net "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/proxy"
"github.com/v2ray/v2ray-core/transport/ray"
v2net "v2ray.com/core/common/net"
"v2ray.com/core/proxy"
"v2ray.com/core/transport/ray"
)
type TestPacketDispatcher struct {

View File

@@ -3,7 +3,7 @@ package dns
import (
"net"
v2net "github.com/v2ray/v2ray-core/common/net"
v2net "v2ray.com/core/common/net"
)
type Config struct {

View File

@@ -7,13 +7,13 @@ import (
"errors"
"net"
v2net "github.com/v2ray/v2ray-core/common/net"
v2net "v2ray.com/core/common/net"
)
func (this *Config) UnmarshalJSON(data []byte) error {
type JsonConfig struct {
Servers []v2net.AddressJson `json:"servers"`
Hosts map[string]v2net.AddressJson `json:"hosts"`
Servers []v2net.AddressPB `json:"servers"`
Hosts map[string]v2net.AddressPB `json:"hosts"`
}
jsonConfig := new(JsonConfig)
if err := json.Unmarshal(data, jsonConfig); err != nil {
@@ -21,16 +21,17 @@ func (this *Config) UnmarshalJSON(data []byte) error {
}
this.NameServers = make([]v2net.Destination, len(jsonConfig.Servers))
for idx, server := range jsonConfig.Servers {
this.NameServers[idx] = v2net.UDPDestination(server.Address, v2net.Port(53))
this.NameServers[idx] = v2net.UDPDestination(server.AsAddress(), v2net.Port(53))
}
if jsonConfig.Hosts != nil {
this.Hosts = make(map[string]net.IP)
for domain, ip := range jsonConfig.Hosts {
if ip.Address.Family().IsDomain() {
return errors.New(ip.Address.String() + " is not an IP.")
for domain, ipOrDomain := range jsonConfig.Hosts {
ip := ipOrDomain.GetIp()
if ip == nil {
return errors.New(ipOrDomain.AsAddress().String() + " is not an IP.")
}
this.Hosts[domain] = ip.Address.IP()
this.Hosts[domain] = net.IP(ip)
}
}

View File

@@ -6,9 +6,9 @@ import (
"encoding/json"
"testing"
. "github.com/v2ray/v2ray-core/app/dns"
v2net "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/testing/assert"
. "v2ray.com/core/app/dns"
v2net "v2ray.com/core/common/net"
"v2ray.com/core/testing/assert"
)
func TestConfigParsing(t *testing.T) {

View File

@@ -3,7 +3,7 @@ package dns
import (
"net"
"github.com/v2ray/v2ray-core/app"
"v2ray.com/core/app"
)
const (

View File

@@ -5,13 +5,13 @@ import (
"sync"
"time"
"github.com/v2ray/v2ray-core/app/dispatcher"
"github.com/v2ray/v2ray-core/common/alloc"
"github.com/v2ray/v2ray-core/common/dice"
"github.com/v2ray/v2ray-core/common/log"
v2net "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/proxy"
"github.com/v2ray/v2ray-core/transport/internet/udp"
"v2ray.com/core/app/dispatcher"
"v2ray.com/core/common/alloc"
"v2ray.com/core/common/dice"
"v2ray.com/core/common/log"
v2net "v2ray.com/core/common/net"
"v2ray.com/core/proxy"
"v2ray.com/core/transport/internet/udp"
"github.com/miekg/dns"
)
@@ -59,7 +59,7 @@ func NewUDPNameServer(address v2net.Destination, dispatcher dispatcher.PacketDis
return s
}
// @Private
// Private: Visible for testing.
func (this *UDPNameServer) Cleanup() {
expiredRequests := make([]uint16, 0, 16)
now := time.Now()
@@ -77,7 +77,7 @@ func (this *UDPNameServer) Cleanup() {
expiredRequests = nil
}
// @Private
// Private: Visible for testing.
func (this *UDPNameServer) AssignUnusedID(response chan<- *ARecord) uint16 {
var id uint16
this.Lock()
@@ -102,7 +102,7 @@ func (this *UDPNameServer) AssignUnusedID(response chan<- *ARecord) uint16 {
return id
}
// @Private
// Private: Visible for testing.
func (this *UDPNameServer) HandleResponse(dest v2net.Destination, payload *alloc.Buffer) {
msg := new(dns.Msg)
err := msg.Unpack(payload.Value)

View File

@@ -5,9 +5,9 @@ import (
"sync"
"time"
"github.com/v2ray/v2ray-core/app"
"github.com/v2ray/v2ray-core/app/dispatcher"
"github.com/v2ray/v2ray-core/common/log"
"v2ray.com/core/app"
"v2ray.com/core/app/dispatcher"
"v2ray.com/core/common/log"
"github.com/miekg/dns"
)
@@ -60,7 +60,7 @@ func (this *CacheServer) Release() {
}
//@Private
// Private: Visible for testing.
func (this *CacheServer) GetCached(domain string) []net.IP {
this.RLock()
defer this.RUnlock()

View File

@@ -4,16 +4,16 @@ import (
"net"
"testing"
"github.com/v2ray/v2ray-core/app"
"github.com/v2ray/v2ray-core/app/dispatcher"
dispatchers "github.com/v2ray/v2ray-core/app/dispatcher/impl"
. "github.com/v2ray/v2ray-core/app/dns"
"github.com/v2ray/v2ray-core/app/proxyman"
v2net "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/proxy"
"github.com/v2ray/v2ray-core/proxy/freedom"
"github.com/v2ray/v2ray-core/testing/assert"
"github.com/v2ray/v2ray-core/transport/internet"
"v2ray.com/core/app"
"v2ray.com/core/app/dispatcher"
dispatchers "v2ray.com/core/app/dispatcher/impl"
. "v2ray.com/core/app/dns"
"v2ray.com/core/app/proxyman"
v2net "v2ray.com/core/common/net"
"v2ray.com/core/proxy"
"v2ray.com/core/proxy/freedom"
"v2ray.com/core/testing/assert"
"v2ray.com/core/transport/internet"
)
func TestDnsAdd(t *testing.T) {

View File

@@ -3,8 +3,8 @@ package proxyman
import (
"sync"
"github.com/v2ray/v2ray-core/app"
"github.com/v2ray/v2ray-core/proxy"
"v2ray.com/core/app"
"v2ray.com/core/proxy"
)
const (

View File

@@ -1,15 +1,13 @@
package router
import (
"errors"
"v2ray.com/core/common"
)
type ConfigObjectCreator func([]byte) (interface{}, error)
var (
configCache map[string]ConfigObjectCreator
ErrRouterNotFound = errors.New("Router not found.")
)
func RegisterRouterConfig(strategy string, creator ConfigObjectCreator) error {
@@ -21,7 +19,7 @@ func RegisterRouterConfig(strategy string, creator ConfigObjectCreator) error {
func CreateRouterConfig(strategy string, data []byte) (interface{}, error) {
creator, found := configCache[strategy]
if !found {
return nil, ErrRouterNotFound
return nil, common.ErrObjectNotFound
}
return creator(data)
}

View File

@@ -5,7 +5,7 @@ package router
import (
"encoding/json"
"github.com/v2ray/v2ray-core/common/log"
"v2ray.com/core/common/log"
)
func (this *Config) UnmarshalJSON(data []byte) error {

View File

@@ -1,9 +1,10 @@
package router
import (
"github.com/v2ray/v2ray-core/app"
"github.com/v2ray/v2ray-core/common"
v2net "github.com/v2ray/v2ray-core/common/net"
"v2ray.com/core/app"
"v2ray.com/core/common"
"v2ray.com/core/common/log"
v2net "v2ray.com/core/common/net"
)
const (
@@ -24,7 +25,9 @@ var (
)
func RegisterRouter(name string, factory RouterFactory) error {
// TODO: check name
if _, found := routerCache[name]; found {
return common.ErrDuplicatedName
}
routerCache[name] = factory
return nil
}
@@ -33,5 +36,6 @@ func CreateRouter(name string, rawConfig interface{}, space app.Space) (Router,
if factory, found := routerCache[name]; found {
return factory.Create(rawConfig, space)
}
return nil, ErrRouterNotFound
log.Error("Router: not found: ", name)
return nil, common.ErrObjectNotFound
}

View File

@@ -13,7 +13,7 @@ import (
"strconv"
"strings"
v2net "github.com/v2ray/v2ray-core/common/net"
v2net "v2ray.com/core/common/net"
)
const (
@@ -65,7 +65,7 @@ func main() {
fmt.Fprintln(file, "package rules")
fmt.Fprintln(file, "import (")
fmt.Fprintln(file, "v2net \"github.com/v2ray/v2ray-core/common/net\"")
fmt.Fprintln(file, "v2net \"v2ray.com/core/common/net\"")
fmt.Fprintln(file, ")")
fmt.Fprintln(file, "var (")

File diff suppressed because it is too large Load Diff

View File

@@ -5,7 +5,7 @@ package rules
import (
"encoding/json"
"github.com/v2ray/v2ray-core/common/log"
"v2ray.com/core/common/log"
)
func parseChinaIPRule(data []byte) (*Rule, error) {

View File

@@ -5,8 +5,8 @@ package rules_test
import (
"testing"
. "github.com/v2ray/v2ray-core/app/router/rules"
"github.com/v2ray/v2ray-core/testing/assert"
. "v2ray.com/core/app/router/rules"
"v2ray.com/core/testing/assert"
)
func TestChinaIPJson(t *testing.T) {

View File

@@ -4,9 +4,9 @@ import (
"net"
"testing"
. "github.com/v2ray/v2ray-core/app/router/rules"
v2net "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/testing/assert"
. "v2ray.com/core/app/router/rules"
v2net "v2ray.com/core/common/net"
"v2ray.com/core/testing/assert"
)
func makeDestination(ip string) v2net.Destination {

View File

@@ -4,7 +4,7 @@ package rules
import (
"encoding/json"
"github.com/v2ray/v2ray-core/common/log"
"v2ray.com/core/common/log"
)
func parseChinaSitesRule(data []byte) (*Rule, error) {

View File

@@ -5,8 +5,8 @@ package rules_test
import (
"testing"
. "github.com/v2ray/v2ray-core/app/router/rules"
"github.com/v2ray/v2ray-core/testing/assert"
. "v2ray.com/core/app/router/rules"
"v2ray.com/core/testing/assert"
)
func TestChinaSitesJson(t *testing.T) {

View File

@@ -3,9 +3,9 @@ package rules_test
import (
"testing"
. "github.com/v2ray/v2ray-core/app/router/rules"
v2net "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/testing/assert"
. "v2ray.com/core/app/router/rules"
v2net "v2ray.com/core/common/net"
"v2ray.com/core/testing/assert"
)
func makeDomainDestination(domain string) v2net.Destination {

View File

@@ -5,7 +5,7 @@ import (
"regexp"
"strings"
v2net "github.com/v2ray/v2ray-core/common/net"
v2net "v2ray.com/core/common/net"
)
type Condition interface {

View File

@@ -1,7 +1,7 @@
package rules
import (
v2net "github.com/v2ray/v2ray-core/common/net"
v2net "v2ray.com/core/common/net"
)
type Rule struct {

View File

@@ -7,10 +7,10 @@ import (
"errors"
"strings"
router "github.com/v2ray/v2ray-core/app/router"
"github.com/v2ray/v2ray-core/common/collect"
"github.com/v2ray/v2ray-core/common/log"
v2net "github.com/v2ray/v2ray-core/common/net"
router "v2ray.com/core/app/router"
"v2ray.com/core/common/collect"
"v2ray.com/core/common/log"
v2net "v2ray.com/core/common/net"
)
type JsonRule struct {

View File

@@ -5,9 +5,9 @@ package rules_test
import (
"testing"
. "github.com/v2ray/v2ray-core/app/router/rules"
v2net "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/testing/assert"
. "v2ray.com/core/app/router/rules"
v2net "v2ray.com/core/common/net"
"v2ray.com/core/testing/assert"
)
func TestDomainRule(t *testing.T) {

View File

@@ -3,11 +3,11 @@ package rules
import (
"errors"
"github.com/v2ray/v2ray-core/app"
"github.com/v2ray/v2ray-core/app/dns"
"github.com/v2ray/v2ray-core/app/router"
"github.com/v2ray/v2ray-core/common/log"
v2net "github.com/v2ray/v2ray-core/common/net"
"v2ray.com/core/app"
"v2ray.com/core/app/dns"
"v2ray.com/core/app/router"
"v2ray.com/core/common/log"
v2net "v2ray.com/core/common/net"
)
var (
@@ -41,7 +41,7 @@ func (this *Router) Release() {
}
// @Private
// Private: Visible for testing.
func (this *Router) ResolveIP(dest v2net.Destination) []v2net.Destination {
ips := this.dnsServer.Get(dest.Address().Domain())
if len(ips) == 0 {

View File

@@ -3,15 +3,15 @@ package rules_test
import (
"testing"
"github.com/v2ray/v2ray-core/app"
"github.com/v2ray/v2ray-core/app/dispatcher"
dispatchers "github.com/v2ray/v2ray-core/app/dispatcher/impl"
"github.com/v2ray/v2ray-core/app/dns"
"github.com/v2ray/v2ray-core/app/proxyman"
"github.com/v2ray/v2ray-core/app/router"
. "github.com/v2ray/v2ray-core/app/router/rules"
v2net "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/testing/assert"
"v2ray.com/core/app"
"v2ray.com/core/app/dispatcher"
dispatchers "v2ray.com/core/app/dispatcher/impl"
"v2ray.com/core/app/dns"
"v2ray.com/core/app/proxyman"
"v2ray.com/core/app/router"
. "v2ray.com/core/app/router/rules"
v2net "v2ray.com/core/common/net"
"v2ray.com/core/testing/assert"
)
func TestSimpleRouter(t *testing.T) {

View File

@@ -3,7 +3,7 @@ package app
import (
"errors"
"github.com/v2ray/v2ray-core/common"
"v2ray.com/core/common"
)
var (

View File

@@ -5,7 +5,7 @@ import (
"hash"
"io"
"github.com/v2ray/v2ray-core/common/serial"
"v2ray.com/core/common/serial"
)
const (
@@ -52,6 +52,7 @@ func (b *Buffer) Clear() *Buffer {
return b
}
// Reset resets this Buffer into its original state.
func (b *Buffer) Reset() *Buffer {
b.offset = defaultOffset
b.Value = b.head

View File

@@ -1,6 +1,8 @@
package alloc
import (
"os"
"strconv"
"sync"
)
@@ -14,14 +16,14 @@ type BufferPool struct {
allocator *sync.Pool
}
func NewBufferPool(bufferSize, poolSize int) *BufferPool {
func NewBufferPool(bufferSize, poolSize uint32) *BufferPool {
pool := &BufferPool{
chain: make(chan []byte, poolSize),
allocator: &sync.Pool{
New: func() interface{} { return make([]byte, bufferSize) },
},
}
for i := 0; i < poolSize; i++ {
for i := uint32(0); i < poolSize; i++ {
pool.chain <- make([]byte, bufferSize)
}
return pool
@@ -51,10 +53,32 @@ func (p *BufferPool) Free(buffer *Buffer) {
const (
SmallBufferSize = 1600 - defaultOffset
BufferSize = 8*1024 - defaultOffset
LargeBufferSize = 64*1024 - defaultOffset
mediumBufferByteSize = 8 * 1024
BufferSize = mediumBufferByteSize - defaultOffset
largeBufferByteSize = 64 * 1024
LargeBufferSize = largeBufferByteSize - defaultOffset
PoolSizeEnvKey = "v2ray.buffer.size"
)
var smallPool = NewBufferPool(1600, 256)
var mediumPool = NewBufferPool(8*1024, 1024)
var largePool = NewBufferPool(64*1024, 32)
var (
smallPool = NewBufferPool(1600, 256)
mediumPool *BufferPool
largePool *BufferPool
)
func init() {
var size uint32 = 20
sizeStr := os.Getenv(PoolSizeEnvKey)
if len(sizeStr) > 0 {
customSize, err := strconv.ParseUint(sizeStr, 10, 32)
if err == nil {
size = uint32(customSize)
}
}
totalByteSize := size * 1024 * 1024
mediumPool = NewBufferPool(mediumBufferByteSize, totalByteSize/4*3/mediumBufferByteSize)
largePool = NewBufferPool(largeBufferByteSize, totalByteSize/4/largeBufferByteSize)
}

View File

@@ -3,8 +3,8 @@ package alloc_test
import (
"testing"
. "github.com/v2ray/v2ray-core/common/alloc"
"github.com/v2ray/v2ray-core/testing/assert"
. "v2ray.com/core/common/alloc"
"v2ray.com/core/testing/assert"
)
func TestBufferClear(t *testing.T) {

View File

@@ -7,6 +7,6 @@ func NewStringList(raw []string) *StringList {
return &list
}
func (this *StringList) Len() int {
return len(*this)
func (this StringList) Len() int {
return len(this)
}

View File

@@ -6,8 +6,8 @@ import (
"encoding/json"
"testing"
. "github.com/v2ray/v2ray-core/common/collect"
"github.com/v2ray/v2ray-core/testing/assert"
. "v2ray.com/core/common/collect"
"v2ray.com/core/testing/assert"
)
func TestStringListUnmarshalError(t *testing.T) {
@@ -18,3 +18,13 @@ func TestStringListUnmarshalError(t *testing.T) {
err := json.Unmarshal([]byte(rawJson), list)
assert.Error(err).IsNotNil()
}
func TestStringListLen(t *testing.T) {
assert := assert.On(t)
rawJson := `"a, b, c, d"`
list := new(StringList)
err := json.Unmarshal([]byte(rawJson), list)
assert.Error(err).IsNil()
assert.Int(list.Len()).Equals(4)
}

View File

@@ -9,6 +9,8 @@ import (
var (
ErrObjectReleased = errors.New("Object already released.")
ErrBadConfiguration = errors.New("Bad configuration.")
ErrObjectNotFound = errors.New("Object not found.")
ErrDuplicatedName = errors.New("Duplicated name.")
)
// Releasable interface is for those types that can release its members.

View File

@@ -4,7 +4,7 @@ import (
"crypto/cipher"
"testing"
. "github.com/v2ray/v2ray-core/common/crypto"
. "v2ray.com/core/common/crypto"
)
const benchSize = 1024 * 1024
@@ -13,6 +13,7 @@ func benchmarkStream(b *testing.B, c cipher.Stream) {
b.SetBytes(benchSize)
input := make([]byte, benchSize)
output := make([]byte, benchSize)
b.ResetTimer()
for i := 0; i < b.N; i++ {
c.XORKeyStream(output, input)
}

View File

@@ -3,7 +3,7 @@ package crypto
import (
"crypto/cipher"
"github.com/v2ray/v2ray-core/common/crypto/internal"
"v2ray.com/core/common/crypto/internal"
)
// NewChaCha20Stream creates a new Chacha20 encryption/descryption stream based on give key and IV.

View File

@@ -5,8 +5,8 @@ import (
"encoding/hex"
"testing"
. "github.com/v2ray/v2ray-core/common/crypto"
"github.com/v2ray/v2ray-core/testing/assert"
. "v2ray.com/core/common/crypto"
"v2ray.com/core/testing/assert"
)
func mustDecodeHex(s string) []byte {

3
common/crypto/crypto.go Normal file
View File

@@ -0,0 +1,3 @@
// Provides common crypto libraries for V2Ray.
package crypto

View File

@@ -4,7 +4,7 @@ import (
"crypto/cipher"
"io"
"github.com/v2ray/v2ray-core/common"
"v2ray.com/core/common"
)
type CryptionReader struct {

View File

@@ -4,7 +4,7 @@ import (
"io"
"sync"
"github.com/v2ray/v2ray-core/common/alloc"
"v2ray.com/core/common/alloc"
)
type BufferedReader struct {

View File

@@ -3,9 +3,9 @@ package io_test
import (
"testing"
"github.com/v2ray/v2ray-core/common/alloc"
. "github.com/v2ray/v2ray-core/common/io"
"github.com/v2ray/v2ray-core/testing/assert"
"v2ray.com/core/common/alloc"
. "v2ray.com/core/common/io"
"v2ray.com/core/testing/assert"
)
func TestBufferedReader(t *testing.T) {

View File

@@ -4,7 +4,7 @@ import (
"io"
"sync"
"github.com/v2ray/v2ray-core/common/alloc"
"v2ray.com/core/common/alloc"
)
type BufferedWriter struct {

View File

@@ -3,9 +3,9 @@ package io_test
import (
"testing"
"github.com/v2ray/v2ray-core/common/alloc"
. "github.com/v2ray/v2ray-core/common/io"
"github.com/v2ray/v2ray-core/testing/assert"
"v2ray.com/core/common/alloc"
. "v2ray.com/core/common/io"
"v2ray.com/core/testing/assert"
)
func TestBufferedWriter(t *testing.T) {

View File

@@ -4,7 +4,7 @@ import (
"io"
"sync"
"github.com/v2ray/v2ray-core/common/alloc"
"v2ray.com/core/common/alloc"
)
type ChainWriter struct {

View File

@@ -4,7 +4,7 @@ import (
"io"
"sync"
"github.com/v2ray/v2ray-core/common/alloc"
"v2ray.com/core/common/alloc"
)
type ChanReader struct {
@@ -22,7 +22,7 @@ func NewChanReader(stream Reader) *ChanReader {
return this
}
// @Private
// Private: Visible for testing.
func (this *ChanReader) Fill() {
b, err := this.stream.Read()
this.current = b

View File

@@ -1,10 +1,10 @@
package io // import "github.com/v2ray/v2ray-core/common/io"
package io
import (
"io"
"github.com/v2ray/v2ray-core/common"
"github.com/v2ray/v2ray-core/common/alloc"
"v2ray.com/core/common"
"v2ray.com/core/common/alloc"
)
// Reader extends io.Reader with alloc.Buffer.

View File

@@ -4,9 +4,9 @@ import (
"bytes"
"testing"
"github.com/v2ray/v2ray-core/common/alloc"
. "github.com/v2ray/v2ray-core/common/io"
"github.com/v2ray/v2ray-core/testing/assert"
"v2ray.com/core/common/alloc"
. "v2ray.com/core/common/io"
"v2ray.com/core/testing/assert"
)
func TestAdaptiveReader(t *testing.T) {

View File

@@ -1,7 +1,7 @@
package io
import (
"github.com/v2ray/v2ray-core/common/log"
"v2ray.com/core/common/log"
)
func Pipe(reader Reader, writer Writer) error {

View File

@@ -3,8 +3,8 @@ package io
import (
"io"
"github.com/v2ray/v2ray-core/common"
"github.com/v2ray/v2ray-core/common/alloc"
"v2ray.com/core/common"
"v2ray.com/core/common/alloc"
)
// Writer extends io.Writer with alloc.Buffer.

View File

@@ -5,9 +5,9 @@ import (
"crypto/rand"
"testing"
"github.com/v2ray/v2ray-core/common/alloc"
. "github.com/v2ray/v2ray-core/common/io"
"github.com/v2ray/v2ray-core/testing/assert"
"v2ray.com/core/common/alloc"
. "v2ray.com/core/common/io"
"v2ray.com/core/testing/assert"
)
func TestAdaptiveWriter(t *testing.T) {

View File

@@ -5,7 +5,8 @@ package loader
import (
"encoding/json"
"github.com/v2ray/v2ray-core/common/log"
"v2ray.com/core/common"
"v2ray.com/core/common/log"
)
type JSONConfigLoader struct {
@@ -42,7 +43,7 @@ func (this *JSONConfigLoader) Load(raw []byte) (interface{}, string, error) {
rawID, found := obj[this.idKey]
if !found {
log.Error(this.idKey, " not found in JSON content.")
return nil, "", ErrConfigIDKeyNotFound
return nil, "", common.ErrObjectNotFound
}
var id string
if err := json.Unmarshal(rawID, &id); err != nil {
@@ -53,7 +54,7 @@ func (this *JSONConfigLoader) Load(raw []byte) (interface{}, string, error) {
configValue, found := obj[this.configKey]
if !found {
log.Error(this.configKey, " not found in JSON content.")
return nil, "", ErrConfigIDKeyNotFound
return nil, "", common.ErrObjectNotFound
}
rawConfig = configValue
}

View File

@@ -2,12 +2,11 @@ package loader
import (
"errors"
"v2ray.com/core/common"
)
var (
ErrConfigIDKeyNotFound = errors.New("Config ID key is not found.")
ErrConfigIDExists = errors.New("Config ID already exists.")
ErrUnknownConfigID = errors.New("Unknown config ID.")
ErrUnknownConfigID = errors.New("Unknown config ID.")
)
type ConfigCreator func() interface{}
@@ -31,7 +30,7 @@ func NewBaseConfigLoader() *BaseConfigLoader {
func (this *BaseConfigLoader) RegisterCreator(id string, creator ConfigCreator) error {
if _, found := this.creators[id]; found {
return ErrConfigIDExists
return common.ErrDuplicatedName
}
this.creators[id] = creator

View File

@@ -1,7 +1,7 @@
package log
import (
"github.com/v2ray/v2ray-core/common/log/internal"
"v2ray.com/core/common/log/internal"
)
// AccessStatus is the status of an access request from clients.

View File

@@ -4,8 +4,8 @@ import (
"fmt"
"strings"
"github.com/v2ray/v2ray-core/common"
"github.com/v2ray/v2ray-core/common/serial"
"v2ray.com/core/common"
"v2ray.com/core/common/serial"
)
func InterfaceToString(value interface{}) string {

View File

@@ -3,8 +3,8 @@ package internal_test
import (
"testing"
. "github.com/v2ray/v2ray-core/common/log/internal"
"github.com/v2ray/v2ray-core/testing/assert"
. "v2ray.com/core/common/log/internal"
"v2ray.com/core/testing/assert"
)
func TestAccessLog(t *testing.T) {

View File

@@ -5,8 +5,8 @@ import (
"os"
"time"
"github.com/v2ray/v2ray-core/common/platform"
"github.com/v2ray/v2ray-core/common/signal"
"v2ray.com/core/common/platform"
"v2ray.com/core/common/signal"
)
type LogWriter interface {

View File

@@ -1,7 +1,7 @@
package log
import (
"github.com/v2ray/v2ray-core/common/log/internal"
"v2ray.com/core/common/log/internal"
)
type LogLevel int

View File

@@ -3,8 +3,8 @@ package net
import (
"net"
"github.com/v2ray/v2ray-core/common/log"
"github.com/v2ray/v2ray-core/common/predicate"
"v2ray.com/core/common/log"
"v2ray.com/core/common/predicate"
)
var (
@@ -186,3 +186,13 @@ func (this *domainAddress) Equals(another Address) bool {
}
return this.Domain() == anotherDomain.Domain()
}
func (this *AddressPB) AsAddress() Address {
switch addr := this.Address.(type) {
case *AddressPB_Ip:
return IPAddress(addr.Ip)
case *AddressPB_Domain:
return DomainAddress(addr.Domain)
}
panic("Common|Net: Invalid AddressPB.")
}

164
common/net/address.pb.go Normal file
View File

@@ -0,0 +1,164 @@
// Code generated by protoc-gen-go.
// source: v2ray.com/core/common/net/address.proto
// DO NOT EDIT!
/*
Package net is a generated protocol buffer package.
It is generated from these files:
v2ray.com/core/common/net/address.proto
v2ray.com/core/common/net/port.proto
It has these top-level messages:
AddressPB
PortRange
*/
package net
import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
type AddressPB struct {
// Types that are valid to be assigned to Address:
// *AddressPB_Ip
// *AddressPB_Domain
Address isAddressPB_Address `protobuf_oneof:"address"`
}
func (m *AddressPB) Reset() { *m = AddressPB{} }
func (m *AddressPB) String() string { return proto.CompactTextString(m) }
func (*AddressPB) ProtoMessage() {}
func (*AddressPB) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
type isAddressPB_Address interface {
isAddressPB_Address()
}
type AddressPB_Ip struct {
Ip []byte `protobuf:"bytes,1,opt,name=ip,proto3,oneof"`
}
type AddressPB_Domain struct {
Domain string `protobuf:"bytes,2,opt,name=domain,oneof"`
}
func (*AddressPB_Ip) isAddressPB_Address() {}
func (*AddressPB_Domain) isAddressPB_Address() {}
func (m *AddressPB) GetAddress() isAddressPB_Address {
if m != nil {
return m.Address
}
return nil
}
func (m *AddressPB) GetIp() []byte {
if x, ok := m.GetAddress().(*AddressPB_Ip); ok {
return x.Ip
}
return nil
}
func (m *AddressPB) GetDomain() string {
if x, ok := m.GetAddress().(*AddressPB_Domain); ok {
return x.Domain
}
return ""
}
// XXX_OneofFuncs is for the internal use of the proto package.
func (*AddressPB) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{}) {
return _AddressPB_OneofMarshaler, _AddressPB_OneofUnmarshaler, _AddressPB_OneofSizer, []interface{}{
(*AddressPB_Ip)(nil),
(*AddressPB_Domain)(nil),
}
}
func _AddressPB_OneofMarshaler(msg proto.Message, b *proto.Buffer) error {
m := msg.(*AddressPB)
// address
switch x := m.Address.(type) {
case *AddressPB_Ip:
b.EncodeVarint(1<<3 | proto.WireBytes)
b.EncodeRawBytes(x.Ip)
case *AddressPB_Domain:
b.EncodeVarint(2<<3 | proto.WireBytes)
b.EncodeStringBytes(x.Domain)
case nil:
default:
return fmt.Errorf("AddressPB.Address has unexpected type %T", x)
}
return nil
}
func _AddressPB_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error) {
m := msg.(*AddressPB)
switch tag {
case 1: // address.ip
if wire != proto.WireBytes {
return true, proto.ErrInternalBadWireType
}
x, err := b.DecodeRawBytes(true)
m.Address = &AddressPB_Ip{x}
return true, err
case 2: // address.domain
if wire != proto.WireBytes {
return true, proto.ErrInternalBadWireType
}
x, err := b.DecodeStringBytes()
m.Address = &AddressPB_Domain{x}
return true, err
default:
return false, nil
}
}
func _AddressPB_OneofSizer(msg proto.Message) (n int) {
m := msg.(*AddressPB)
// address
switch x := m.Address.(type) {
case *AddressPB_Ip:
n += proto.SizeVarint(1<<3 | proto.WireBytes)
n += proto.SizeVarint(uint64(len(x.Ip)))
n += len(x.Ip)
case *AddressPB_Domain:
n += proto.SizeVarint(2<<3 | proto.WireBytes)
n += proto.SizeVarint(uint64(len(x.Domain)))
n += len(x.Domain)
case nil:
default:
panic(fmt.Sprintf("proto: unexpected type %T in oneof", x))
}
return n
}
func init() {
proto.RegisterType((*AddressPB)(nil), "com.v2ray.core.common.net.AddressPB")
}
func init() { proto.RegisterFile("v2ray.com/core/common/net/address.proto", fileDescriptor0) }
var fileDescriptor0 = []byte{
// 148 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xe2, 0x52, 0x2f, 0x33, 0x2a, 0x4a,
0xac, 0xd4, 0x4b, 0xce, 0xcf, 0xd5, 0x4f, 0xce, 0x2f, 0x4a, 0xd5, 0x4f, 0xce, 0xcf, 0xcd, 0xcd,
0xcf, 0xd3, 0xcf, 0x4b, 0x2d, 0xd1, 0x4f, 0x4c, 0x49, 0x29, 0x4a, 0x2d, 0x2e, 0xd6, 0x2b, 0x28,
0xca, 0x2f, 0xc9, 0x17, 0x92, 0x4c, 0xce, 0xcf, 0xd5, 0x83, 0x29, 0x2e, 0x4a, 0xd5, 0x83, 0x28,
0xd4, 0xcb, 0x4b, 0x2d, 0x51, 0x72, 0xe2, 0xe2, 0x74, 0x84, 0xa8, 0x0d, 0x70, 0x12, 0x12, 0xe0,
0x62, 0xca, 0x2c, 0x90, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0xf1, 0x60, 0x08, 0x62, 0xca, 0x2c, 0x10,
0x92, 0xe0, 0x62, 0x4b, 0xc9, 0xcf, 0x4d, 0xcc, 0xcc, 0x93, 0x60, 0x52, 0x60, 0xd4, 0xe0, 0xf4,
0x60, 0x08, 0x82, 0xf2, 0x9d, 0x38, 0xb9, 0xd8, 0xa1, 0x96, 0x38, 0xb1, 0x46, 0x31, 0xe7, 0xa5,
0x96, 0x24, 0xb1, 0x81, 0x2d, 0x33, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0x3b, 0x04, 0x63, 0x74,
0x97, 0x00, 0x00, 0x00,
}

11
common/net/address.proto Normal file
View File

@@ -0,0 +1,11 @@
syntax = "proto3";
package com.v2ray.core.common.net;
option go_package = "net";
message AddressPB {
oneof address {
bytes ip = 1;
string domain = 2;
}
}

View File

@@ -6,15 +6,22 @@ import (
"encoding/json"
)
type AddressJson struct {
Address Address
}
func (this *AddressJson) UnmarshalJSON(data []byte) error {
func (this *AddressPB) UnmarshalJSON(data []byte) error {
var rawStr string
if err := json.Unmarshal(data, &rawStr); err != nil {
return err
}
this.Address = ParseAddress(rawStr)
addr := ParseAddress(rawStr)
switch addr.Family() {
case AddressFamilyIPv4, AddressFamilyIPv6:
this.Address = &AddressPB_Ip{
Ip: []byte(addr.IP()),
}
case AddressFamilyDomain:
this.Address = &AddressPB_Domain{
Domain: addr.Domain(),
}
}
return nil
}

View File

@@ -4,42 +4,37 @@ package net_test
import (
"encoding/json"
"net"
"testing"
. "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/testing/assert"
. "v2ray.com/core/common/net"
"v2ray.com/core/testing/assert"
)
func TestIPParsing(t *testing.T) {
assert := assert.On(t)
rawJson := "\"8.8.8.8\""
var address AddressJson
var address AddressPB
err := json.Unmarshal([]byte(rawJson), &address)
assert.Error(err).IsNil()
assert.Bool(address.Address.Family().Either(AddressFamilyIPv4)).IsTrue()
assert.Bool(address.Address.Family().Either(AddressFamilyDomain)).IsFalse()
assert.Bool(address.Address.IP().Equal(net.ParseIP("8.8.8.8"))).IsTrue()
assert.Bytes(address.GetIp()).Equals([]byte{8, 8, 8, 8})
}
func TestDomainParsing(t *testing.T) {
assert := assert.On(t)
rawJson := "\"v2ray.com\""
var address AddressJson
var address AddressPB
err := json.Unmarshal([]byte(rawJson), &address)
assert.Error(err).IsNil()
assert.Bool(address.Address.Family().Either(AddressFamilyIPv4)).IsFalse()
assert.Bool(address.Address.Family().Either(AddressFamilyDomain)).IsTrue()
assert.String(address.Address.Domain()).Equals("v2ray.com")
assert.String(address.GetDomain()).Equals("v2ray.com")
}
func TestInvalidAddressJson(t *testing.T) {
assert := assert.On(t)
rawJson := "1234"
var address AddressJson
var address AddressPB
err := json.Unmarshal([]byte(rawJson), &address)
assert.Error(err).IsNotNil()
}

View File

@@ -4,8 +4,8 @@ import (
"net"
"testing"
v2net "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/testing/assert"
v2net "v2ray.com/core/common/net"
"v2ray.com/core/testing/assert"
)
func TestIPv4Address(t *testing.T) {

View File

@@ -3,8 +3,8 @@ package net_test
import (
"testing"
v2net "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/testing/assert"
v2net "v2ray.com/core/common/net"
"v2ray.com/core/testing/assert"
)
func TestTCPDestination(t *testing.T) {

View File

@@ -4,8 +4,8 @@ import (
"net"
"testing"
. "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/testing/assert"
. "v2ray.com/core/common/net"
"v2ray.com/core/testing/assert"
)
func parseCIDR(str string) *net.IPNet {

View File

@@ -1,2 +1,2 @@
// Package net contains common network utilities.
package net // import "github.com/v2ray/v2ray-core/common/net"
package net

View File

@@ -3,7 +3,7 @@ package net
import (
"strings"
"github.com/v2ray/v2ray-core/common/collect"
"v2ray.com/core/common/collect"
)
const (
@@ -15,6 +15,9 @@ const (
// KCPNetwork represents the KCP network.
KCPNetwork = Network("kcp")
// WSNetwork represents the Websocket over HTTP network.
WSNetwork = Network("ws")
)
// Network represents a communication network on internet.

View File

@@ -5,7 +5,7 @@ package net
import (
"encoding/json"
"github.com/v2ray/v2ray-core/common/collect"
"v2ray.com/core/common/collect"
)
func (this *NetworkList) UnmarshalJSON(data []byte) error {

View File

@@ -6,8 +6,8 @@ import (
"encoding/json"
"testing"
. "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/testing/assert"
. "v2ray.com/core/common/net"
"v2ray.com/core/testing/assert"
)
func TestArrayNetworkList(t *testing.T) {

View File

@@ -4,7 +4,7 @@ import (
"errors"
"strconv"
"github.com/v2ray/v2ray-core/common/serial"
"v2ray.com/core/common/serial"
)
var (
@@ -23,8 +23,8 @@ func PortFromBytes(port []byte) Port {
// PortFromInt converts an integer to a Port.
// @error when the integer is not positive or larger then 65535
func PortFromInt(v int) (Port, error) {
if v <= 0 || v > 65535 {
func PortFromInt(v uint32) (Port, error) {
if v > 65535 {
return Port(0), ErrInvalidPortRange
}
return Port(v), nil
@@ -33,11 +33,11 @@ func PortFromInt(v int) (Port, error) {
// PortFromString converts a string to a Port.
// @error when the string is not an integer or the integral value is a not a valid Port.
func PortFromString(s string) (Port, error) {
v, err := strconv.Atoi(s)
v, err := strconv.ParseUint(s, 10, 32)
if err != nil {
return Port(0), ErrInvalidPortRange
}
return PortFromInt(v)
return PortFromInt(uint32(v))
}
// Value return the correspoding uint16 value of this Port.
@@ -55,13 +55,15 @@ func (this Port) String() string {
return serial.Uint16ToString(this.Value())
}
// PortRange represents a range of ports.
type PortRange struct {
From Port
To Port
func (this PortRange) FromPort() Port {
return Port(this.From)
}
func (this PortRange) ToPort() Port {
return Port(this.To)
}
// Contains returns true if the given port is within the range of this PortRange.
func (this PortRange) Contains(port Port) bool {
return this.From <= port && port <= this.To
return this.FromPort() <= port && port <= this.ToPort()
}

44
common/net/port.pb.go Normal file
View File

@@ -0,0 +1,44 @@
// Code generated by protoc-gen-go.
// source: v2ray.com/core/common/net/port.proto
// DO NOT EDIT!
package net
import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// PortRange represents a range of ports.
type PortRange struct {
From uint32 `protobuf:"varint,1,opt,name=From,json=from" json:"From,omitempty"`
To uint32 `protobuf:"varint,2,opt,name=To,json=to" json:"To,omitempty"`
}
func (m *PortRange) Reset() { *m = PortRange{} }
func (m *PortRange) String() string { return proto.CompactTextString(m) }
func (*PortRange) ProtoMessage() {}
func (*PortRange) Descriptor() ([]byte, []int) { return fileDescriptor1, []int{0} }
func init() {
proto.RegisterType((*PortRange)(nil), "com.v2ray.core.common.net.PortRange")
}
func init() { proto.RegisterFile("v2ray.com/core/common/net/port.proto", fileDescriptor1) }
var fileDescriptor1 = []byte{
// 137 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x34, 0xcc, 0xb1, 0x0a, 0xc2, 0x40,
0x0c, 0x87, 0x71, 0x7a, 0x56, 0xc1, 0x03, 0x1d, 0x6e, 0xaa, 0x9b, 0x88, 0x83, 0x53, 0x02, 0xfa,
0x06, 0x0e, 0xce, 0x52, 0x9c, 0xdc, 0xea, 0x11, 0x9d, 0x92, 0x7f, 0x09, 0x41, 0xf0, 0xed, 0x85,
0x8a, 0xeb, 0xc7, 0x8f, 0x2f, 0xef, 0xdf, 0x47, 0x1f, 0x3e, 0x54, 0xa1, 0x5c, 0xe1, 0xc2, 0x15,
0xaa, 0x30, 0x36, 0x09, 0x1e, 0xe1, 0x41, 0xa3, 0x23, 0x50, 0x36, 0x15, 0x4a, 0x7f, 0xe9, 0x42,
0x3f, 0x45, 0x26, 0xb1, 0xe3, 0xbc, 0xbc, 0xc2, 0xa3, 0x1f, 0xec, 0x25, 0xa5, 0xe4, 0xf6, 0xe2,
0xd0, 0xae, 0xd9, 0x36, 0x87, 0x55, 0xdf, 0x3e, 0x1d, 0x5a, 0xd6, 0x39, 0xdd, 0xd0, 0xa5, 0xa9,
0xa4, 0xc0, 0x79, 0x7e, 0x9f, 0x99, 0xc4, 0x63, 0x31, 0x9d, 0x4f, 0xdf, 0x00, 0x00, 0x00, 0xff,
0xff, 0xc3, 0x9d, 0x1a, 0x33, 0x81, 0x00, 0x00, 0x00,
}

10
common/net/port.proto Normal file
View File

@@ -0,0 +1,10 @@
syntax = "proto3";
package com.v2ray.core.common.net;
option go_package = "net";
// PortRange represents a range of ports.
message PortRange {
uint32 From = 1;
uint32 To = 2;
}

View File

@@ -6,11 +6,11 @@ import (
"encoding/json"
"strings"
"github.com/v2ray/v2ray-core/common/log"
"v2ray.com/core/common/log"
)
func parseIntPort(data []byte) (Port, error) {
var intPort int
var intPort uint32
err := json.Unmarshal(data, &intPort)
if err != nil {
return Port(0), err
@@ -48,15 +48,15 @@ func parseStringPort(data []byte) (Port, Port, error) {
func (this *PortRange) UnmarshalJSON(data []byte) error {
port, err := parseIntPort(data)
if err == nil {
this.From = port
this.To = port
this.From = uint32(port)
this.To = uint32(port)
return nil
}
from, to, err := parseStringPort(data)
if err == nil {
this.From = from
this.To = to
this.From = uint32(from)
this.To = uint32(to)
if this.From > this.To {
log.Error("Invalid port range ", this.From, " -> ", this.To)
return ErrInvalidPortRange

View File

@@ -6,8 +6,8 @@ import (
"encoding/json"
"testing"
. "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/testing/assert"
. "v2ray.com/core/common/net"
"v2ray.com/core/testing/assert"
)
func TestIntPort(t *testing.T) {
@@ -17,8 +17,8 @@ func TestIntPort(t *testing.T) {
err := json.Unmarshal([]byte("1234"), &portRange)
assert.Error(err).IsNil()
assert.Uint16(portRange.From.Value()).Equals(uint16(1234))
assert.Uint16(portRange.To.Value()).Equals(uint16(1234))
assert.Uint32(portRange.From).Equals(1234)
assert.Uint32(portRange.To).Equals(1234)
}
func TestOverRangeIntPort(t *testing.T) {
@@ -39,8 +39,8 @@ func TestSingleStringPort(t *testing.T) {
err := json.Unmarshal([]byte("\"1234\""), &portRange)
assert.Error(err).IsNil()
assert.Uint16(portRange.From.Value()).Equals(uint16(1234))
assert.Uint16(portRange.To.Value()).Equals(uint16(1234))
assert.Uint32(portRange.From).Equals(1234)
assert.Uint32(portRange.To).Equals(1234)
}
func TestStringPairPort(t *testing.T) {
@@ -50,8 +50,8 @@ func TestStringPairPort(t *testing.T) {
err := json.Unmarshal([]byte("\"1234-5678\""), &portRange)
assert.Error(err).IsNil()
assert.Uint16(portRange.From.Value()).Equals(uint16(1234))
assert.Uint16(portRange.To.Value()).Equals(uint16(5678))
assert.Uint32(portRange.From).Equals(1234)
assert.Uint32(portRange.To).Equals(5678)
}
func TestOverRangeStringPort(t *testing.T) {

View File

@@ -3,16 +3,16 @@ package net_test
import (
"testing"
. "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/testing/assert"
. "v2ray.com/core/common/net"
"v2ray.com/core/testing/assert"
)
func TestPortRangeContains(t *testing.T) {
assert := assert.On(t)
portRange := &PortRange{
From: Port(53),
To: Port(53),
From: 53,
To: 53,
}
assert.Bool(portRange.Contains(Port(53))).IsTrue()
}

View File

@@ -1,10 +0,0 @@
package testing
import (
"github.com/v2ray/v2ray-core/common/dice"
v2net "github.com/v2ray/v2ray-core/common/net"
)
func PickPort() v2net.Port {
return v2net.Port(30000 + dice.Roll(20000))
}

View File

@@ -11,15 +11,15 @@ var (
)
type TimeOutReader struct {
timeout int
timeout uint32
connection net.Conn
worker io.Reader
}
func NewTimeOutReader(timeout int /* seconds */, connection net.Conn) *TimeOutReader {
func NewTimeOutReader(timeout uint32 /* seconds */, connection net.Conn) *TimeOutReader {
reader := &TimeOutReader{
connection: connection,
timeout: -100,
timeout: 0,
}
reader.SetTimeOut(timeout)
return reader
@@ -29,12 +29,12 @@ func (reader *TimeOutReader) Read(p []byte) (int, error) {
return reader.worker.Read(p)
}
func (reader *TimeOutReader) GetTimeOut() int {
func (reader *TimeOutReader) GetTimeOut() uint32 {
return reader.timeout
}
func (reader *TimeOutReader) SetTimeOut(value int) {
if value == reader.timeout {
func (reader *TimeOutReader) SetTimeOut(value uint32) {
if reader.worker != nil && value == reader.timeout {
return
}
reader.timeout = value
@@ -56,7 +56,7 @@ func (reader *TimeOutReader) Release() {
}
type timedReaderWorker struct {
timeout int
timeout uint32
connection net.Conn
}

View File

@@ -3,17 +3,17 @@ package net_test
import (
"testing"
. "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/testing/assert"
. "v2ray.com/core/common/net"
"v2ray.com/core/testing/assert"
)
func TestTimeOutSettings(t *testing.T) {
assert := assert.On(t)
reader := NewTimeOutReader(8, nil)
assert.Int(reader.GetTimeOut()).Equals(8)
assert.Uint32(reader.GetTimeOut()).Equals(8)
reader.SetTimeOut(8) // no op
assert.Int(reader.GetTimeOut()).Equals(8)
assert.Uint32(reader.GetTimeOut()).Equals(8)
reader.SetTimeOut(9)
assert.Int(reader.GetTimeOut()).Equals(9)
assert.Uint32(reader.GetTimeOut()).Equals(9)
}

View File

@@ -3,3 +3,9 @@ package protocol
type Account interface {
Equals(Account) bool
}
type AsAccount interface {
AsAccount() (Account, error)
}
type NewAccountFactory func() AsAccount

View File

@@ -1,8 +1,8 @@
package protocol
import (
v2net "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/common/uuid"
v2net "v2ray.com/core/common/net"
"v2ray.com/core/common/uuid"
)
type RequestCommand byte
@@ -77,6 +77,6 @@ type CommandSwitchAccount struct {
Port v2net.Port
ID *uuid.UUID
AlterIds uint16
Level UserLevel
Level uint32
ValidMin byte
}

View File

@@ -3,8 +3,8 @@ package protocol_test
import (
"testing"
. "github.com/v2ray/v2ray-core/common/protocol"
"github.com/v2ray/v2ray-core/testing/assert"
. "v2ray.com/core/common/protocol"
"v2ray.com/core/testing/assert"
)
func TestRequestOptionSet(t *testing.T) {

View File

@@ -6,7 +6,7 @@ import (
"errors"
"hash"
"github.com/v2ray/v2ray-core/common/uuid"
"v2ray.com/core/common/uuid"
)
const (

View File

@@ -3,10 +3,10 @@ package protocol_test
import (
"testing"
"github.com/v2ray/v2ray-core/common/predicate"
. "github.com/v2ray/v2ray-core/common/protocol"
"github.com/v2ray/v2ray-core/common/uuid"
"github.com/v2ray/v2ray-core/testing/assert"
"v2ray.com/core/common/predicate"
. "v2ray.com/core/common/protocol"
"v2ray.com/core/common/uuid"
"v2ray.com/core/testing/assert"
)
func TestCmdKey(t *testing.T) {

View File

@@ -46,7 +46,7 @@ func (this *ServerList) GetServer(idx uint32) *ServerSpec {
}
}
// @Private
// Private: Visible for testing.
func (this *ServerList) RemoveServer(idx uint32) {
n := len(this.servers)
this.servers[idx] = this.servers[n-1]

View File

@@ -4,18 +4,18 @@ import (
"testing"
"time"
v2net "github.com/v2ray/v2ray-core/common/net"
. "github.com/v2ray/v2ray-core/common/protocol"
"github.com/v2ray/v2ray-core/testing/assert"
v2net "v2ray.com/core/common/net"
. "v2ray.com/core/common/protocol"
"v2ray.com/core/testing/assert"
)
func TestServerList(t *testing.T) {
assert := assert.On(t)
list := NewServerList()
list.AddServer(NewServerSpec(v2net.TCPDestination(v2net.LocalHostIP, v2net.Port(1)), AlwaysValid()))
list.AddServer(NewServerSpec(nil, v2net.TCPDestination(v2net.LocalHostIP, v2net.Port(1)), AlwaysValid()))
assert.Uint32(list.Size()).Equals(1)
list.AddServer(NewServerSpec(v2net.TCPDestination(v2net.LocalHostIP, v2net.Port(2)), BeforeTime(time.Now().Add(time.Second))))
list.AddServer(NewServerSpec(nil, v2net.TCPDestination(v2net.LocalHostIP, v2net.Port(2)), BeforeTime(time.Now().Add(time.Second))))
assert.Uint32(list.Size()).Equals(2)
server := list.GetServer(1)
@@ -32,9 +32,9 @@ func TestServerPicker(t *testing.T) {
assert := assert.On(t)
list := NewServerList()
list.AddServer(NewServerSpec(v2net.TCPDestination(v2net.LocalHostIP, v2net.Port(1)), AlwaysValid()))
list.AddServer(NewServerSpec(v2net.TCPDestination(v2net.LocalHostIP, v2net.Port(2)), BeforeTime(time.Now().Add(time.Second))))
list.AddServer(NewServerSpec(v2net.TCPDestination(v2net.LocalHostIP, v2net.Port(3)), BeforeTime(time.Now().Add(time.Second))))
list.AddServer(NewServerSpec(nil, v2net.TCPDestination(v2net.LocalHostIP, v2net.Port(1)), AlwaysValid()))
list.AddServer(NewServerSpec(nil, v2net.TCPDestination(v2net.LocalHostIP, v2net.Port(2)), BeforeTime(time.Now().Add(time.Second))))
list.AddServer(NewServerSpec(nil, v2net.TCPDestination(v2net.LocalHostIP, v2net.Port(3)), BeforeTime(time.Now().Add(time.Second))))
picker := NewRoundRobinServerPicker(list)
server := picker.PickServer()

View File

@@ -4,8 +4,8 @@ import (
"sync"
"time"
"github.com/v2ray/v2ray-core/common/dice"
v2net "github.com/v2ray/v2ray-core/common/net"
"v2ray.com/core/common/dice"
v2net "v2ray.com/core/common/net"
)
type ValidationStrategy interface {
@@ -45,19 +45,26 @@ func (this *TimeoutValidStrategy) Invalidate() {
type ServerSpec struct {
sync.RWMutex
dest v2net.Destination
users []*User
valid ValidationStrategy
dest v2net.Destination
users []*User
valid ValidationStrategy
newAccount NewAccountFactory
}
func NewServerSpec(dest v2net.Destination, valid ValidationStrategy, users ...*User) *ServerSpec {
func NewServerSpec(newAccount NewAccountFactory, dest v2net.Destination, valid ValidationStrategy, users ...*User) *ServerSpec {
return &ServerSpec{
dest: dest,
users: users,
valid: valid,
dest: dest,
users: users,
valid: valid,
newAccount: newAccount,
}
}
func NewServerSpecFromPB(newAccount NewAccountFactory, spec ServerSpecPB) *ServerSpec {
dest := v2net.TCPDestination(spec.Address.AsAddress(), v2net.Port(spec.Port))
return NewServerSpec(newAccount, dest, AlwaysValid(), spec.Users...)
}
func (this *ServerSpec) Destination() v2net.Destination {
return this.dest
}
@@ -66,9 +73,13 @@ func (this *ServerSpec) HasUser(user *User) bool {
this.RLock()
defer this.RUnlock()
account := user.Account
accountA, err := user.GetTypedAccount(this.newAccount())
if err != nil {
return false
}
for _, u := range this.users {
if u.Account.Equals(account) {
accountB, err := u.GetTypedAccount(this.newAccount())
if err == nil && accountA.Equals(accountB) {
return true
}
}

View File

@@ -0,0 +1,81 @@
// Code generated by protoc-gen-go.
// source: v2ray.com/core/common/protocol/server_spec.proto
// DO NOT EDIT!
/*
Package protocol is a generated protocol buffer package.
It is generated from these files:
v2ray.com/core/common/protocol/server_spec.proto
v2ray.com/core/common/protocol/user.proto
It has these top-level messages:
ServerSpecPB
User
*/
package protocol
import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
import com_v2ray_core_common_net "v2ray.com/core/common/net"
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
type ServerSpecPB struct {
Address *com_v2ray_core_common_net.AddressPB `protobuf:"bytes,1,opt,name=address" json:"address,omitempty"`
Port uint32 `protobuf:"varint,2,opt,name=port" json:"port,omitempty"`
Users []*User `protobuf:"bytes,3,rep,name=users" json:"users,omitempty"`
}
func (m *ServerSpecPB) Reset() { *m = ServerSpecPB{} }
func (m *ServerSpecPB) String() string { return proto.CompactTextString(m) }
func (*ServerSpecPB) ProtoMessage() {}
func (*ServerSpecPB) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
func (m *ServerSpecPB) GetAddress() *com_v2ray_core_common_net.AddressPB {
if m != nil {
return m.Address
}
return nil
}
func (m *ServerSpecPB) GetUsers() []*User {
if m != nil {
return m.Users
}
return nil
}
func init() {
proto.RegisterType((*ServerSpecPB)(nil), "com.v2ray.core.common.protocol.ServerSpecPB")
}
func init() { proto.RegisterFile("v2ray.com/core/common/protocol/server_spec.proto", fileDescriptor0) }
var fileDescriptor0 = []byte{
// 209 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x84, 0x8e, 0x3f, 0x4b, 0xc5, 0x30,
0x14, 0xc5, 0x89, 0xf5, 0x1f, 0x51, 0x97, 0x4c, 0xa5, 0x83, 0x14, 0x11, 0xac, 0xcb, 0x8d, 0xd4,
0xcd, 0x41, 0xb0, 0x9f, 0xa0, 0xb4, 0xb8, 0xb8, 0x48, 0x4d, 0xef, 0x66, 0x7a, 0xc3, 0x4d, 0x2c,
0xf8, 0x65, 0xfc, 0xac, 0xf2, 0x92, 0x97, 0xad, 0xbc, 0xb7, 0x1d, 0x0e, 0xe7, 0x77, 0xce, 0x91,
0x4f, 0x6b, 0xcb, 0xd3, 0x2f, 0x18, 0xb2, 0xda, 0x10, 0xa3, 0x36, 0x64, 0x2d, 0x2d, 0xda, 0x31,
0x05, 0x32, 0xf4, 0xad, 0x3d, 0xf2, 0x8a, 0xfc, 0xe9, 0x1d, 0x1a, 0x88, 0xa6, 0xba, 0x35, 0x64,
0x21, 0x53, 0x8c, 0x90, 0x08, 0xc8, 0x44, 0xf5, 0xb0, 0xdd, 0xb8, 0x60, 0xd0, 0xd3, 0x3c, 0x33,
0x7a, 0x9f, 0xb2, 0xd5, 0xe3, 0x91, 0xe9, 0x1f, 0x8f, 0x9c, 0xa2, 0x77, 0x7f, 0x42, 0x5e, 0x8f,
0xf1, 0xc9, 0xe8, 0xd0, 0xf4, 0x9d, 0x7a, 0x95, 0x17, 0xfb, 0xb2, 0x52, 0xd4, 0xa2, 0xb9, 0x6a,
0xef, 0x61, 0xfb, 0xd6, 0x82, 0x01, 0xde, 0x52, 0xb2, 0xef, 0x86, 0x0c, 0x29, 0x25, 0x4f, 0x1d,
0x71, 0x28, 0x4f, 0x6a, 0xd1, 0xdc, 0x0c, 0x51, 0xab, 0x17, 0x79, 0xb6, 0x9b, 0xf4, 0x65, 0x51,
0x17, 0x07, 0x1a, 0xf3, 0x3f, 0x78, 0xf7, 0xc8, 0x43, 0x42, 0x3a, 0xf9, 0x71, 0x99, 0xfd, 0xaf,
0xf3, 0xa8, 0x9e, 0xff, 0x03, 0x00, 0x00, 0xff, 0xff, 0xde, 0x92, 0x28, 0x40, 0x5b, 0x01, 0x00,
0x00,
}

View File

@@ -0,0 +1,13 @@
syntax = "proto3";
import "v2ray.com/core/common/net/address.proto";
import "v2ray.com/core/common/protocol/user.proto";
package com.v2ray.core.common.protocol;
option go_package = "protocol";
message ServerSpecPB {
com.v2ray.core.common.net.AddressPB address = 1;
uint32 port = 2;
repeated com.v2ray.core.common.protocol.User users = 3;
}

View File

@@ -4,41 +4,10 @@ import (
"testing"
"time"
v2net "github.com/v2ray/v2ray-core/common/net"
. "github.com/v2ray/v2ray-core/common/protocol"
"github.com/v2ray/v2ray-core/testing/assert"
. "v2ray.com/core/common/protocol"
"v2ray.com/core/testing/assert"
)
type TestAccount struct {
id int
}
func (this *TestAccount) Equals(account Account) bool {
return account.(*TestAccount).id == this.id
}
func TestServerSpecUser(t *testing.T) {
assert := assert.On(t)
account := &TestAccount{
id: 0,
}
user := NewUser(UserLevel(0), "")
user.Account = account
rec := NewServerSpec(v2net.TCPDestination(v2net.DomainAddress("v2ray.com"), 80), AlwaysValid(), user)
assert.Bool(rec.HasUser(user)).IsTrue()
account2 := &TestAccount{
id: 1,
}
user2 := NewUser(UserLevel(0), "")
user2.Account = account2
assert.Bool(rec.HasUser(user2)).IsFalse()
rec.AddUser(user2)
assert.Bool(rec.HasUser(user2)).IsTrue()
}
func TestAlwaysValidStrategy(t *testing.T) {
assert := assert.On(t)

View File

@@ -3,8 +3,8 @@ package protocol
import (
"time"
"github.com/v2ray/v2ray-core/common/dice"
"github.com/v2ray/v2ray-core/common/serial"
"v2ray.com/core/common/dice"
"v2ray.com/core/common/serial"
)
type Timestamp int64

View File

@@ -4,8 +4,8 @@ import (
"testing"
"time"
. "github.com/v2ray/v2ray-core/common/protocol"
"github.com/v2ray/v2ray-core/testing/assert"
. "v2ray.com/core/common/protocol"
"v2ray.com/core/testing/assert"
)
func TestGenerateRandomInt64InRange(t *testing.T) {

View File

@@ -1,35 +1,44 @@
package protocol
type UserLevel byte
import (
"errors"
const (
UserLevelAdmin = UserLevel(255)
UserLevelUntrusted = UserLevel(0)
"github.com/golang/protobuf/proto"
"github.com/golang/protobuf/ptypes"
)
type User struct {
Account Account
Level UserLevel
Email string
}
var (
ErrUserMissing = errors.New("User is not specified.")
ErrAccountMissing = errors.New("Account is not specified.")
ErrNonMessageType = errors.New("Not a protobuf message.")
)
func NewUser(level UserLevel, email string) *User {
return &User{
Level: level,
Email: email,
func (this *User) GetTypedAccount(account AsAccount) (Account, error) {
anyAccount := this.GetAccount()
if anyAccount == nil {
return nil, ErrAccountMissing
}
protoAccount, ok := account.(proto.Message)
if !ok {
return nil, ErrNonMessageType
}
err := ptypes.UnmarshalAny(anyAccount, protoAccount)
if err != nil {
return nil, err
}
return account.AsAccount()
}
type UserSettings struct {
PayloadReadTimeout int
}
func GetUserSettings(level UserLevel) UserSettings {
func (this *User) GetSettings() UserSettings {
settings := UserSettings{
PayloadReadTimeout: 120,
}
if level > 0 {
if this.Level > 0 {
settings.PayloadReadTimeout = 0
}
return settings
}
type UserSettings struct {
PayloadReadTimeout uint32
}

View File

@@ -0,0 +1,55 @@
// Code generated by protoc-gen-go.
// source: v2ray.com/core/common/protocol/user.proto
// DO NOT EDIT!
package protocol
import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
import google_protobuf "github.com/golang/protobuf/ptypes/any"
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
type User struct {
Level uint32 `protobuf:"varint,1,opt,name=level" json:"level,omitempty"`
Email string `protobuf:"bytes,2,opt,name=email" json:"email,omitempty"`
Account *google_protobuf.Any `protobuf:"bytes,3,opt,name=account" json:"account,omitempty"`
}
func (m *User) Reset() { *m = User{} }
func (m *User) String() string { return proto.CompactTextString(m) }
func (*User) ProtoMessage() {}
func (*User) Descriptor() ([]byte, []int) { return fileDescriptor1, []int{0} }
func (m *User) GetAccount() *google_protobuf.Any {
if m != nil {
return m.Account
}
return nil
}
func init() {
proto.RegisterType((*User)(nil), "com.v2ray.core.common.protocol.User")
}
func init() { proto.RegisterFile("v2ray.com/core/common/protocol/user.proto", fileDescriptor1) }
var fileDescriptor1 = []byte{
// 179 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x34, 0x8e, 0xcb, 0xaa, 0xc2, 0x30,
0x10, 0x86, 0xc9, 0x39, 0x5e, 0x23, 0x6e, 0x4a, 0x17, 0xd5, 0x85, 0x14, 0x57, 0x75, 0x33, 0x81,
0xfa, 0x04, 0xfa, 0x08, 0x05, 0x37, 0xee, 0xd2, 0x61, 0x2c, 0x42, 0x92, 0x91, 0xf4, 0x02, 0x79,
0x7b, 0xb1, 0x21, 0xbb, 0xf9, 0x66, 0xbe, 0xe1, 0xff, 0xe5, 0x65, 0xaa, 0xbd, 0x0e, 0x80, 0x6c,
0x15, 0xb2, 0x27, 0x85, 0x6c, 0x2d, 0x3b, 0xf5, 0xf1, 0x3c, 0x30, 0xb2, 0x51, 0x63, 0x4f, 0x1e,
0x66, 0xca, 0x4e, 0xc8, 0x16, 0x92, 0xee, 0x09, 0xa2, 0x0a, 0x49, 0x3d, 0x1e, 0x3a, 0xe6, 0xce,
0x50, 0xfc, 0x6d, 0xc7, 0x97, 0xd2, 0x2e, 0xc4, 0xeb, 0xb9, 0x95, 0x8b, 0x47, 0x4f, 0x3e, 0xcb,
0xe5, 0xd2, 0xd0, 0x44, 0xa6, 0x10, 0xa5, 0xa8, 0xf6, 0x4d, 0x84, 0xdf, 0x96, 0xac, 0x7e, 0x9b,
0xe2, 0xaf, 0x14, 0xd5, 0xb6, 0x89, 0x90, 0x81, 0x5c, 0x6b, 0x44, 0x1e, 0xdd, 0x50, 0xfc, 0x97,
0xa2, 0xda, 0xd5, 0x39, 0xc4, 0x00, 0x48, 0x01, 0x70, 0x73, 0xa1, 0x49, 0xd2, 0x5d, 0x3e, 0x37,
0xa9, 0x4a, 0xbb, 0x9a, 0xa7, 0xeb, 0x37, 0x00, 0x00, 0xff, 0xff, 0xfa, 0x7e, 0xbf, 0xfa, 0xde,
0x00, 0x00, 0x00,
}

Some files were not shown because too many files have changed in this diff Show More