V2Ray 10 лет назад
Родитель
Сommit
a45498da45
6 измененных файлов с 66 добавлено и 69 удалено
  1. 19 20
      io/jsonvconfigmarshaller.go
  2. 17 17
      io/vmessreader.go
  3. 7 9
      net/vmesshandler.go
  4. 7 7
      vconfig.go
  5. 4 4
      vid.go
  6. 12 12
      vpoint.go

+ 19 - 20
io/jsonvconfigmarshaller.go

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

+ 17 - 17
io/vmessreader.go

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

+ 7 - 9
net/vmesshandler.go

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

+ 7 - 7
vconfig.go

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

+ 4 - 4
vid.go

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

+ 12 - 12
vpoint.go

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