fix typo, http test

This commit is contained in:
Page Fault
2020-06-17 14:00:44 +00:00
parent 65c932df92
commit dd1294be14
7 changed files with 37 additions and 20 deletions
+1 -1
View File
@@ -114,7 +114,7 @@ func (s *ServerAPI) SetUsers(stream TrojanServerService_SetUsersServer) error {
user.SetIPLimit(int(req.IpLimit))
}
if req.TrafficTotal.DownloadTraffic > 0 || req.TrafficTotal.UploadTraffic > 0 {
user.SetTrafficTotal(req.TrafficTotal.DownloadTraffic, req.TrafficTotal.UploadTraffic)
user.SetTraffic(req.TrafficTotal.DownloadTraffic, req.TrafficTotal.UploadTraffic)
}
}
}
+1 -1
View File
@@ -107,7 +107,7 @@ func TestServerAPI(t *testing.T) {
},
TrafficTotal: &Traffic{
DownloadTraffic: 1,
UploadTraffic: 1,
UploadTraffic: 1,
},
})
go func() {
+1 -1
View File
@@ -15,7 +15,7 @@ var creators = make(map[KeyType]Creator)
// Creator creates default config struct for a module
type Creator func() interface{}
// RegisterConfigCreator registers a config structs for parsing
// RegisterConfigCreator registers a config struct for parsing
func RegisterConfigCreator(name KeyType, creator Creator) {
name += "_CONFIG"
creators[name] = creator
+27
View File
@@ -0,0 +1,27 @@
package custom
import "github.com/p4gefau1t/trojan-go/config"
const Name = "CUSTOM"
type Node struct {
Protocol string
Tag string
Config interface{}
}
type StackConfig struct {
NodeList []Node `json,yaml:"node"`
Path [][]string `json,yaml:"path"`
}
type Config struct {
Inbound StackConfig `json,yaml:"inbound"`
Outbound StackConfig `json,yaml:"outbound"`
}
func init() {
config.RegisterConfigCreator(Name, func() interface{} {
return new(Config)
})
}
+1 -1
View File
@@ -124,7 +124,7 @@ func (u *User) Hash() string {
return u.hash
}
func (u *User) SetTrafficTotal(send, recv uint64) {
func (u *User) SetTraffic(send, recv uint64) {
atomic.StoreUint64(&u.sent, send)
atomic.StoreUint64(&u.recv, recv)
}
+3 -3
View File
@@ -18,9 +18,9 @@ type TrafficMeter interface {
ResetTraffic()
GetAndResetTraffic() (sent, recv uint64)
GetSpeed() (sent, recv uint64)
SetSpeedLimit(send, recv int)
GetSpeedLimit() (send, recv int)
SetTrafficTotal(send, recv uint64)
SetSpeedLimit(sent, recv int)
GetSpeedLimit() (sent, recv int)
SetTraffic(sent, recv uint64)
}
type IPRecorder interface {
+3 -13
View File
@@ -37,19 +37,9 @@ func TestHTTP(t *testing.T) {
fmt.Println(req)
ioutil.ReadAll(req.Body)
req.Body.Close()
resp := `HTTP/1.1 200 OK
Date: Mon, 19 Jul 2004 16:18:20 GMT
Server: Apache
Last-Modified: Sat, 10 Jul 2004 17:29:19 GMT
ETag: "1d0325-2470-40f0276f"
Accept-Ranges: bytes
Content-Length: 4
Connection: close
Content-Type: text/html
1234
`
_, err = conn.Write([]byte(resp))
resp, err := http.Get("http://127.0.0.1:" + util.HTTPPort)
common.Must(err)
err = resp.Write(conn)
common.Must(err)
buf := [100]byte{}
_, err = conn.Read(buf[:])