diff --git a/admin/shell.go b/admin/interactive.go similarity index 100% rename from admin/shell.go rename to admin/interactive.go diff --git a/common/file.go b/common/file.go index 4b0c30f..03c8cee 100644 --- a/common/file.go +++ b/common/file.go @@ -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 -} diff --git a/common/utils.go b/common/utils.go index 66a32ac..893474c 100644 --- a/common/utils.go +++ b/common/utils.go @@ -7,6 +7,8 @@ import ( "runtime" "strconv" "sync" + + "github.com/cheggaaa/pb/v3" ) var AdminId = "0000000000" @@ -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 { diff --git a/node/init.go b/node/init.go index 2a593b0..8629b0e 100644 --- a/node/init.go +++ b/node/init.go @@ -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) @@ -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) @@ -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) @@ -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") diff --git a/node/reuse.go b/node/reuse.go index f30a06b..8598bb6 100644 --- a/node/reuse.go +++ b/node/reuse.go @@ -13,7 +13,7 @@ import ( //reuse模式下的共用代码 -/*-------------------------端口复用模式下主动连接功能代码--------------------------*/ +/*-------------------------端口复用模式下节点主动连接功能代码--------------------------*/ //初始化时的连接 func StartNodeConnReuse(monitor string, listenPort string, nodeID string, key []byte) (net.Conn, string, error) { for { @@ -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") @@ -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) diff --git a/socks/socks.go b/socks/socks.go index 7da91eb..d86264c 100644 --- a/socks/socks.go +++ b/socks/socks.go @@ -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 != "") { @@ -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]) @@ -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 @@ -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 @@ -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 {