Skip to content

Commit

Permalink
Add note
Browse files Browse the repository at this point in the history
  • Loading branch information
ph4ntonn committed Apr 22, 2020
1 parent dc3cb00 commit ed4104a
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 11 deletions.
File renamed without changes.
8 changes: 0 additions & 8 deletions common/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,3 @@ func ReceiveFile(route string, controlConnToAdmin *net.Conn, FileDataMap *IntStr
}
return
}

//进度条
func NewBar(length int64) *pb.ProgressBar {
bar := pb.New64(int64(length))
bar.SetTemplate(pb.Full)
bar.Set(pb.Bytes, true)
return bar
}
10 changes: 10 additions & 0 deletions common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"runtime"
"strconv"
"sync"

"github.com/cheggaaa/pb/v3"
)

var AdminId = "0000000000"
Expand Down Expand Up @@ -367,6 +369,14 @@ func CheckSystem() (sysType uint32) {
return
}

/*-------------------------进度条生成相关代码--------------------------*/
func NewBar(length int64) *pb.ProgressBar {
bar := pb.New64(int64(length))
bar.SetTemplate(pb.Full)
bar.Set(pb.Bytes, true)
return bar
}

/*-------------------------操作功能性代码--------------------------*/
//uint32转换至string类型
func Uint32Str(num uint32) string {
Expand Down
4 changes: 4 additions & 0 deletions node/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func init() {
NodeInfo = common.NewNodeInfo()
}

/*-------------------------一般模式下初始化节点代码--------------------------*/
//初始化一个节点连接操作
func StartNodeConn(monitor string, listenPort string, nodeID string, key []byte) (net.Conn, string, error) {
controlConnToUpperNode, err := net.Dial("tcp", monitor)
Expand Down Expand Up @@ -117,6 +118,7 @@ func StartNodeListen(listenPort string, NodeId string, key []byte) {
}
}

/*-------------------------节点主动connect模式代码--------------------------*/
//connect命令代码
func ConnectNextNode(target string, nodeid string, key []byte) bool {
controlConnToNextNode, err := net.Dial("tcp", target)
Expand Down Expand Up @@ -162,6 +164,7 @@ func ConnectNextNode(target string, nodeid string, key []byte) bool {
}
}

/*-------------------------节点被动模式下功能代码--------------------------*/
//被动模式下startnode接收admin重连 && 普通节点被动启动等待上级节点主动连接
func AcceptConnFromUpperNode(listenPort string, nodeid string, key []byte) (net.Conn, string) {
listenAddr := fmt.Sprintf("0.0.0.0:%s", listenPort)
Expand Down Expand Up @@ -199,6 +202,7 @@ func AcceptConnFromUpperNode(listenPort string, nodeid string, key []byte) (net.

}

/*-------------------------一般模式及被动模式下(除了reuse模式)节点互相校验代码--------------------------*/
//发送secret值
func SendSecret(conn net.Conn, key []byte) error {
var NOT_VALID = errors.New("not valid")
Expand Down
6 changes: 3 additions & 3 deletions node/reuse.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

//reuse模式下的共用代码

/*-------------------------端口复用模式下主动连接功能代码--------------------------*/
/*-------------------------端口复用模式下节点主动连接功能代码--------------------------*/
//初始化时的连接
func StartNodeConnReuse(monitor string, listenPort string, nodeID string, key []byte) (net.Conn, string, error) {
for {
Expand Down Expand Up @@ -98,7 +98,7 @@ func ConnectNextNodeReuse(target string, nodeid string, key []byte) bool {
}
}

/*-------------------------端口复用模式下判断、转发功能代码--------------------------*/
/*-------------------------端口复用模式下判断流量、转发流量功能代码--------------------------*/
//发送特征字段
func IfValid(conn net.Conn) error {
var NOT_VALID = errors.New("Not valid")
Expand Down Expand Up @@ -138,7 +138,7 @@ func CheckValid(conn net.Conn, reuse bool, report string) error {
}
}

//不是stowaway的连接,进行代理
//不是来自Stowaway的连接,进行代理
func ProxyStream(conn net.Conn, message []byte, report string) {
reuseAddr := fmt.Sprintf("127.0.0.1:%s", report)
reuseConn, err := net.Dial("tcp", reuseAddr)
Expand Down
6 changes: 6 additions & 0 deletions socks/socks.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"strconv"
)

/*-------------------------Socks5功能代码-------------------------*/
//判断是否需要用户名/密码
func CheckMethod(conntoupper net.Conn, buffer []byte, username string, secret string, clientid uint32, key []byte, currentid string) string {
if buffer[0] == 0x05 {
if buffer[2] == 0x02 && (username != "") {
Expand All @@ -31,6 +33,7 @@ func CheckMethod(conntoupper net.Conn, buffer []byte, username string, secret st
return "RETURN"
}

//如果需要用户名/密码,验证用户合法性
func AuthClient(conntoupper net.Conn, buffer []byte, username string, secret string, clientid uint32, key []byte, currentid string) bool {
ulen := int(buffer[1])
slen := int(buffer[2+ulen])
Expand All @@ -48,6 +51,7 @@ func AuthClient(conntoupper net.Conn, buffer []byte, username string, secret str
}
}

//判断代理方式
func ConfirmTarget(conntoupper net.Conn, buffer []byte, checknum uint32, key []byte, currentid string) (net.Conn, bool, bool) {
len := len(buffer)
connected := false
Expand All @@ -67,6 +71,7 @@ func ConfirmTarget(conntoupper net.Conn, buffer []byte, checknum uint32, key []b
return server, connected, serverflag
}

//如果是代理tcp
func TcpConnect(conntoupper net.Conn, buffer []byte, len int, checknum uint32, key []byte, currentid string) (net.Conn, bool, bool) {
host := ""
var server net.Conn
Expand All @@ -93,6 +98,7 @@ func TcpConnect(conntoupper net.Conn, buffer []byte, len int, checknum uint32, k
return server, true, true
}

//转发流量
func Proxyhttp(conntoupper net.Conn, server net.Conn, checknum uint32, key []byte, currentid string) error {
serverbuffer := make([]byte, 20480)
for {
Expand Down

0 comments on commit ed4104a

Please sign in to comment.