1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2026-01-02 15:25:28 -05:00

Dokodemo proxy

This commit is contained in:
V2Ray
2015-10-30 15:56:46 +01:00
parent f93b29993b
commit c56e17fff9
7 changed files with 197 additions and 3 deletions

View File

@@ -0,0 +1,32 @@
package json
import (
"encoding/json"
"strings"
v2net "github.com/v2ray/v2ray-core/common/net"
)
type NetworkList []string
func (this *NetworkList) UnmarshalJSON(data []byte) error {
var strList []string
err := json.Unmarshal(data, &strList)
if err != nil {
return err
}
*this = make([]string, len(strList))
for idx, str := range strList {
(*this)[idx] = strings.ToLower(str)
}
return nil
}
func (this *NetworkList) HasNetwork(network v2net.Network) bool {
for _, value := range *this {
if value == string(network) {
return true
}
}
return false
}

12
common/net/network.go Normal file
View File

@@ -0,0 +1,12 @@
package net
const (
TCPNetwork = Network("tcp")
UDPNetwork = Network("udp")
)
type Network string
type NetworkList interface {
HasNetwork(Network) bool
}

View File

@@ -22,10 +22,14 @@ func NewTimeOutReader(timeout int, connection net.Conn) *TimeOutReader {
}
func (reader *TimeOutReader) Read(p []byte) (n int, err error) {
deadline := time.Duration(reader.timeout) * time.Second
reader.connection.SetReadDeadline(time.Now().Add(deadline))
if reader.timeout > 0 {
deadline := time.Duration(reader.timeout) * time.Second
reader.connection.SetReadDeadline(time.Now().Add(deadline))
}
n, err = reader.connection.Read(p)
reader.connection.SetReadDeadline(emptyTime)
if reader.timeout > 0 {
reader.connection.SetReadDeadline(emptyTime)
}
return
}