Пример #1
0
func TestConfigTargetParsing(t *testing.T) {
	assert := assert.On(t)

	rawJson := `{
    "vnext": [{
      "address": "127.0.0.1",
      "port": 80,
      "users": [
        {
          "id": "e641f5ad-9397-41e3-bf1a-e8740dfed019",
          "email": "*****@*****.**",
          "level": 255
        }
      ]
    }]
  }`

	rawConfig := new(VMessOutboundConfig)
	err := json.Unmarshal([]byte(rawJson), &rawConfig)
	assert.Error(err).IsNil()

	ts, err := rawConfig.Build()
	assert.Error(err).IsNil()

	iConfig, err := ts.GetInstance()
	assert.Error(err).IsNil()

	config := iConfig.(*outbound.Config)
	specPB := config.Receiver[0]
	spec := protocol.NewServerSpecFromPB(*specPB)
	assert.Destination(spec.Destination()).EqualsString("tcp:127.0.0.1:80")
}
Пример #2
0
// NewClient create a new Shadowsocks client.
func NewClient(ctx context.Context, config *ClientConfig) (*Client, error) {
	serverList := protocol.NewServerList()
	for _, rec := range config.Server {
		serverList.AddServer(protocol.NewServerSpecFromPB(*rec))
	}
	client := &Client{
		serverPicker: protocol.NewRoundRobinServerPicker(serverList),
	}

	return client, nil
}
Пример #3
0
func NewClient(config *ClientConfig, space app.Space, meta *proxy.OutboundHandlerMeta) (*Client, error) {
	serverList := protocol.NewServerList()
	for _, rec := range config.Server {
		serverList.AddServer(protocol.NewServerSpecFromPB(*rec))
	}
	client := &Client{
		serverPicker: protocol.NewRoundRobinServerPicker(serverList),
		meta:         meta,
	}

	return client, nil
}
Пример #4
0
func (v *Factory) Create(space app.Space, rawConfig interface{}, meta *proxy.OutboundHandlerMeta) (proxy.OutboundHandler, error) {
	vOutConfig := rawConfig.(*Config)

	serverList := protocol.NewServerList()
	for _, rec := range vOutConfig.Receiver {
		serverList.AddServer(protocol.NewServerSpecFromPB(*rec))
	}
	handler := &VMessOutboundHandler{
		serverList:   serverList,
		serverPicker: protocol.NewRoundRobinServerPicker(serverList),
		meta:         meta,
	}

	return handler, nil
}
Пример #5
0
func New(ctx context.Context, config *Config) (*VMessOutboundHandler, error) {
	space := app.SpaceFromContext(ctx)
	if space == nil {
		return nil, errors.New("VMess|Outbound: No space in context.")
	}

	serverList := protocol.NewServerList()
	for _, rec := range config.Receiver {
		serverList.AddServer(protocol.NewServerSpecFromPB(*rec))
	}
	handler := &VMessOutboundHandler{
		serverList:   serverList,
		serverPicker: protocol.NewRoundRobinServerPicker(serverList),
	}

	return handler, nil
}
Пример #6
0
func TestSocksOutboundConfig(t *testing.T) {
	assert := assert.On(t)

	rawJson := `{
    "servers": [{
      "address": "127.0.0.1",
      "port": 1234,
      "users": [
        {"user": "******", "pass": "******", "email": "*****@*****.**"}
      ]
    }]
  }`

	config := new(SocksClientConfig)
	err := json.Unmarshal([]byte(rawJson), &config)
	assert.Error(err).IsNil()

	message, err := config.Build()
	assert.Error(err).IsNil()

	iConfig, err := message.GetInstance()
	assert.Error(err).IsNil()

	socksConfig := iConfig.(*socks.ClientConfig)
	assert.Int(len(socksConfig.Server)).Equals(1)

	ss := protocol.NewServerSpecFromPB(*socksConfig.Server[0])
	assert.Destination(ss.Destination()).EqualsString("tcp:127.0.0.1:1234")

	user := ss.PickUser()
	assert.String(user.Email).Equals("*****@*****.**")

	account, err := user.GetTypedAccount()
	assert.Error(err).IsNil()

	socksAccount := account.(*socks.Account)
	assert.String(socksAccount.Username).Equals("test user")
	assert.String(socksAccount.Password).Equals("test pass")
}