format code

pull/298/head
V2Ray 9 years ago
parent 530f749aa3
commit a45498da45

@ -1,38 +1,37 @@
package io package io
import ( import (
"encoding/json" "encoding/json"
_ "fmt" _ "fmt"
"github.com/v2ray/v2ray-core" "github.com/v2ray/v2ray-core"
) )
type JsonVUser struct { type JsonVUser struct {
id string `json:"id"` id string `json:"id"`
email string `json:"email"` email string `json:"email"`
} }
type JsonVConfig struct { type JsonVConfig struct {
RunAs string `json:"runas"` RunAs string `json:"runas"`
Port uint8 `json:"port"` Port uint8 `json:"port"`
Clients []JsonVUser `json:"users"` Clients []JsonVUser `json:"users"`
Protocol string `json:"protocol"` Protocol string `json:"protocol"`
} }
type JsonVConfigUnmarshaller struct { type JsonVConfigUnmarshaller struct {
} }
func StringToVUser(id string) (u core.VUser, err error) { func StringToVUser(id string) (u core.VUser, err error) {
return return
} }
func (*JsonVConfigUnmarshaller) Unmarshall(data []byte) (*core.VConfig, error) { func (*JsonVConfigUnmarshaller) Unmarshall(data []byte) (*core.VConfig, error) {
var jsonConfig JsonVConfig var jsonConfig JsonVConfig
err := json.Unmarshal(data, &jsonConfig) err := json.Unmarshal(data, &jsonConfig)
if err != nil { if err != nil {
return nil, err return nil, err
} }
var vconfig = new(core.VConfig) var vconfig = new(core.VConfig)
vconfig.RunAs = core.VUser{} vconfig.RunAs = core.VUser{}
return vconfig, nil return vconfig, nil
} }

@ -1,32 +1,32 @@
package io package io
import ( import (
"net" "net"
) )
type VMessInput struct { type VMessInput struct {
version byte version byte
userHash [16]byte userHash [16]byte
randHash [256]byte randHash [256]byte
respKey [32]byte respKey [32]byte
iv [16]byte iv [16]byte
command byte command byte
port uint16 port uint16
target [256]byte target [256]byte
data []byte data []byte
} }
type VMessReader struct { type VMessReader struct {
conn *net.Conn conn *net.Conn
} }
func NewVMessReader(conn *net.Conn) (VMessReader, error) { func NewVMessReader(conn *net.Conn) (VMessReader, error) {
var reader VMessReader var reader VMessReader
reader.conn = conn reader.conn = conn
return reader, nil return reader, nil
} }
func (*VMessReader) Read() (VMessInput, error) { func (*VMessReader) Read() (VMessInput, error) {
var input VMessInput var input VMessInput
return input, nil return input, nil
} }

@ -1,19 +1,17 @@
package net package net
import ( import (
"net" "net"
) )
type VMessHandler struct { type VMessHandler struct {
} }
func (*VMessHandler) Listen(port uint8) error { func (*VMessHandler) Listen(port uint8) error {
listener, err := net.Listen("tcp", ":" + string(port)) listener, err := net.Listen("tcp", ":"+string(port))
if err != nil { if err != nil {
return err return err
} }
return nil
return nil
} }

@ -1,20 +1,20 @@
package core package core
type VUser struct { type VUser struct {
id VID id VID
} }
type VConfig struct { type VConfig struct {
RunAs VUser RunAs VUser
Port uint16 Port uint16
AllowedClients []VUser AllowedClients []VUser
AllowedProtocol string AllowedProtocol string
} }
type VConfigMarshaller interface { type VConfigMarshaller interface {
Marshal(config VConfig) ([]byte, error) Marshal(config VConfig) ([]byte, error)
} }
type VConfigUnmarshaller interface { type VConfigUnmarshaller interface {
Unmarshal(data []byte) (VConfig, error) Unmarshal(data []byte) (VConfig, error)
} }

@ -1,8 +1,8 @@
package core package core
import ( import (
"encoding/hex" "encoding/hex"
"fmt" "fmt"
) )
type VID [16]byte type VID [16]byte
@ -11,8 +11,8 @@ var byteGroups = []int{8, 4, 4, 4, 12}
// TODO: leverage a full functional UUID library // TODO: leverage a full functional UUID library
func UUIDToVID(uuid string) (v VID, err error) { func UUIDToVID(uuid string) (v VID, err error) {
text := []byte(uuid) text := []byte(uuid)
if len(text) < 32 { if len(text) < 32 {
err = fmt.Errorf("uuid: invalid UUID string: %s", text) err = fmt.Errorf("uuid: invalid UUID string: %s", text)
return return
} }

@ -1,27 +1,27 @@
package core package core
import ( import (
"fmt" "fmt"
) )
type VPoint struct { type VPoint struct {
config VConfig config VConfig
connHandler ConnectionHandler connHandler ConnectionHandler
} }
func NewVPoint(config *VConfig) (*VPoint, error) { func NewVPoint(config *VConfig) (*VPoint, error) {
var vpoint *VPoint var vpoint *VPoint
return vpoint, nil return vpoint, nil
} }
type ConnectionHandler interface { type ConnectionHandler interface {
Listen(port uint16) error Listen(port uint16) error
} }
func (vp *VPoint) Start() error { func (vp *VPoint) Start() error {
if vp.config.Port <= 0 { if vp.config.Port <= 0 {
return fmt.Errorf("Invalid port %d", vp.config.Port) return fmt.Errorf("Invalid port %d", vp.config.Port)
} }
vp.connHandler.Listen(vp.config.Port) vp.connHandler.Listen(vp.config.Port)
return nil return nil
} }

Loading…
Cancel
Save