1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-26 20:16:55 -05:00

protobuf for dokodemo config

This commit is contained in:
Darien Raymond 2016-09-22 16:49:20 +02:00
parent 88ae8248a5
commit 60f4292882
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
7 changed files with 128 additions and 21 deletions

View File

@ -188,6 +188,9 @@ func (this *domainAddress) Equals(another Address) bool {
} }
func (this *AddressPB) AsAddress() Address { func (this *AddressPB) AsAddress() Address {
if this == nil {
return nil
}
switch addr := this.Address.(type) { switch addr := this.Address.(type) {
case *AddressPB_Ip: case *AddressPB_Ip:
return IPAddress(addr.Ip) return IPAddress(addr.Ip)

View File

@ -4,10 +4,6 @@ import (
v2net "v2ray.com/core/common/net" v2net "v2ray.com/core/common/net"
) )
type Config struct { func (this *Config) GetPredefinedAddress() v2net.Address {
FollowRedirect bool return this.Address.AsAddress()
Address v2net.Address
Port v2net.Port
Network *v2net.NetworkList
Timeout uint32
} }

View File

@ -0,0 +1,85 @@
// Code generated by protoc-gen-go.
// source: v2ray.com/core/proxy/dokodemo/config.proto
// DO NOT EDIT!
/*
Package dokodemo is a generated protocol buffer package.
It is generated from these files:
v2ray.com/core/proxy/dokodemo/config.proto
It has these top-level messages:
Config
*/
package dokodemo
import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
import com_v2ray_core_common_net "v2ray.com/core/common/net"
import com_v2ray_core_common_net1 "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 Config 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"`
NetworkList *com_v2ray_core_common_net1.NetworkList `protobuf:"bytes,3,opt,name=network_list,json=networkList" json:"network_list,omitempty"`
Timeout uint32 `protobuf:"varint,4,opt,name=timeout" json:"timeout,omitempty"`
FollowRedirect bool `protobuf:"varint,5,opt,name=follow_redirect,json=followRedirect" json:"follow_redirect,omitempty"`
}
func (m *Config) Reset() { *m = Config{} }
func (m *Config) String() string { return proto.CompactTextString(m) }
func (*Config) ProtoMessage() {}
func (*Config) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
func (m *Config) GetAddress() *com_v2ray_core_common_net.AddressPB {
if m != nil {
return m.Address
}
return nil
}
func (m *Config) GetNetworkList() *com_v2ray_core_common_net1.NetworkList {
if m != nil {
return m.NetworkList
}
return nil
}
func init() {
proto.RegisterType((*Config)(nil), "com.v2ray.core.proxy.dokodemo.Config")
}
func init() { proto.RegisterFile("v2ray.com/core/proxy/dokodemo/config.proto", fileDescriptor0) }
var fileDescriptor0 = []byte{
// 257 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x7c, 0x90, 0x4d, 0x4b, 0x03, 0x31,
0x10, 0x86, 0x59, 0xad, 0x6d, 0x49, 0xfd, 0x80, 0x9c, 0x82, 0x20, 0x14, 0x11, 0xbb, 0x78, 0x48,
0xa0, 0xde, 0x05, 0xeb, 0x49, 0x10, 0x91, 0x3d, 0x7a, 0x29, 0x35, 0x3b, 0x95, 0xd0, 0x4d, 0x66,
0x99, 0x1d, 0xad, 0xfd, 0xcb, 0xfe, 0x0a, 0x21, 0xd9, 0x20, 0xf4, 0xd0, 0x5b, 0x66, 0x78, 0xf2,
0xbc, 0x6f, 0x22, 0xee, 0xbe, 0xe7, 0xb4, 0xda, 0x69, 0x8b, 0xde, 0x58, 0x24, 0x30, 0x2d, 0xe1,
0xcf, 0xce, 0xd4, 0xb8, 0xc1, 0x1a, 0x3c, 0x1a, 0x8b, 0x61, 0xed, 0x3e, 0x75, 0x4b, 0xc8, 0x28,
0xaf, 0x2c, 0x7a, 0x9d, 0x79, 0x02, 0x1d, 0x59, 0x9d, 0xd9, 0xcb, 0xd9, 0x9e, 0xca, 0xa2, 0xf7,
0x18, 0x4c, 0x00, 0x36, 0xab, 0xba, 0x26, 0xe8, 0xba, 0xe4, 0x39, 0x04, 0x06, 0xe0, 0x2d, 0xd2,
0x26, 0x81, 0xd7, 0xbf, 0x85, 0x18, 0x3e, 0xc5, 0x06, 0xf2, 0x41, 0x8c, 0x7a, 0x89, 0x2a, 0xa6,
0x45, 0x39, 0x99, 0xdf, 0xe8, 0xbd, 0x36, 0xc9, 0xa2, 0x03, 0xb0, 0x7e, 0x4c, 0xe4, 0xdb, 0xa2,
0xca, 0x97, 0xa4, 0x14, 0x83, 0x16, 0x89, 0xd5, 0xd1, 0xb4, 0x28, 0xcf, 0xaa, 0x78, 0x96, 0xcf,
0xe2, 0xb4, 0xcf, 0x5b, 0x36, 0xae, 0x63, 0x75, 0x1c, 0xc5, 0xb7, 0x07, 0xc4, 0xaf, 0x09, 0x7f,
0x71, 0x1d, 0x57, 0x93, 0xf0, 0x3f, 0x48, 0x25, 0x46, 0xec, 0x3c, 0xe0, 0x17, 0xab, 0x41, 0x4c,
0xc8, 0xa3, 0x9c, 0x89, 0x8b, 0x35, 0x36, 0x0d, 0x6e, 0x97, 0x04, 0xb5, 0x23, 0xb0, 0xac, 0x4e,
0xa6, 0x45, 0x39, 0xae, 0xce, 0xd3, 0xba, 0xea, 0xb7, 0x0b, 0xf1, 0x3e, 0xce, 0x5f, 0xf9, 0x31,
0x8c, 0xef, 0xbf, 0xff, 0x0b, 0x00, 0x00, 0xff, 0xff, 0x85, 0x0f, 0xd2, 0x20, 0x9e, 0x01, 0x00,
0x00,
}

View File

@ -0,0 +1,15 @@
syntax = "proto3";
package com.v2ray.core.proxy.dokodemo;
option go_package = "dokodemo";
import "v2ray.com/core/common/net/address.proto";
import "v2ray.com/core/common/net/network.proto";
message Config {
com.v2ray.core.common.net.AddressPB address = 1;
uint32 port = 2;
com.v2ray.core.common.net.NetworkList network_list = 3;
uint32 timeout = 4;
bool follow_redirect = 5;
}

View File

@ -23,10 +23,10 @@ func (this *Config) UnmarshalJSON(data []byte) error {
return errors.New("Dokodemo: Failed to parse config: " + err.Error()) return errors.New("Dokodemo: Failed to parse config: " + err.Error())
} }
if rawConfig.Host != nil { if rawConfig.Host != nil {
this.Address = rawConfig.Host.AsAddress() this.Address = rawConfig.Host
} }
this.Port = rawConfig.PortValue this.Port = uint32(rawConfig.PortValue)
this.Network = rawConfig.NetworkList this.NetworkList = rawConfig.NetworkList
this.Timeout = rawConfig.TimeoutValue this.Timeout = rawConfig.TimeoutValue
this.FollowRedirect = rawConfig.Redirect this.FollowRedirect = rawConfig.Redirect
return nil return nil

View File

@ -32,8 +32,8 @@ type DokodemoDoor struct {
func NewDokodemoDoor(config *Config, space app.Space, meta *proxy.InboundHandlerMeta) *DokodemoDoor { func NewDokodemoDoor(config *Config, space app.Space, meta *proxy.InboundHandlerMeta) *DokodemoDoor {
d := &DokodemoDoor{ d := &DokodemoDoor{
config: config, config: config,
address: config.Address, address: config.GetPredefinedAddress(),
port: config.Port, port: v2net.Port(config.Port),
meta: meta, meta: meta,
} }
space.InitializeApplication(func() error { space.InitializeApplication(func() error {
@ -73,13 +73,13 @@ func (this *DokodemoDoor) Start() error {
} }
this.accepting = true this.accepting = true
if this.config.Network.HasNetwork(v2net.Network_TCP) { if this.config.NetworkList.HasNetwork(v2net.Network_TCP) {
err := this.ListenTCP() err := this.ListenTCP()
if err != nil { if err != nil {
return err return err
} }
} }
if this.config.Network.HasNetwork(v2net.Network_UDP) { if this.config.NetworkList.HasNetwork(v2net.Network_UDP) {
err := this.ListenUDP() err := this.ListenUDP()
if err != nil { if err != nil {
return err return err

View File

@ -54,9 +54,13 @@ func TestDokodemoTCP(t *testing.T) {
port := v2net.Port(dice.Roll(20000) + 10000) port := v2net.Port(dice.Roll(20000) + 10000)
dokodemo := NewDokodemoDoor(&Config{ dokodemo := NewDokodemoDoor(&Config{
Address: v2net.LocalHostIP, Address: &v2net.AddressPB{
Port: tcpServer.Port, Address: &v2net.AddressPB_Ip{
Network: v2net.Network_TCP.AsList(), Ip: v2net.LocalHostIP.IP(),
},
},
Port: uint32(tcpServer.Port),
NetworkList: v2net.Network_TCP.AsList(),
Timeout: 600, Timeout: 600,
}, space, &proxy.InboundHandlerMeta{ }, space, &proxy.InboundHandlerMeta{
Address: v2net.LocalHostIP, Address: v2net.LocalHostIP,
@ -124,9 +128,13 @@ func TestDokodemoUDP(t *testing.T) {
port := v2net.Port(dice.Roll(20000) + 10000) port := v2net.Port(dice.Roll(20000) + 10000)
dokodemo := NewDokodemoDoor(&Config{ dokodemo := NewDokodemoDoor(&Config{
Address: v2net.LocalHostIP, Address: &v2net.AddressPB{
Port: udpServer.Port, Address: &v2net.AddressPB_Ip{
Network: v2net.Network_UDP.AsList(), Ip: v2net.LocalHostIP.IP(),
},
},
Port: uint32(udpServer.Port),
NetworkList: v2net.Network_UDP.AsList(),
Timeout: 600, Timeout: 600,
}, space, &proxy.InboundHandlerMeta{ }, space, &proxy.InboundHandlerMeta{
Address: v2net.LocalHostIP, Address: v2net.LocalHostIP,