mirror of
https://github.com/bolucat/Archive.git
synced 2025-12-24 13:28:37 +08:00
Update On Wed Oct 29 19:43:11 CET 2025
This commit is contained in:
@@ -366,6 +366,7 @@ test-binary:
|
||||
CGO_ENABLED=1 go build -race -ldflags="-X 'github.com/enfein/mieru/v3/pkg/log.LogPrefix=C2'" -o mieru2 cmd/mieru/mieru.go
|
||||
CGO_ENABLED=1 go build -race -ldflags="-X 'github.com/enfein/mieru/v3/pkg/log.LogPrefix=S2'" -o mita2 cmd/mita/mita.go
|
||||
CGO_ENABLED=0 go build test/cmd/exampleapiclient/exampleapiclient.go
|
||||
CGO_ENABLED=0 go build test/cmd/exampleapiserver/exampleapiserver.go
|
||||
CGO_ENABLED=0 go build test/cmd/httpserver/httpserver.go
|
||||
CGO_ENABLED=0 go build test/cmd/sockshttpclient/sockshttpclient.go
|
||||
CGO_ENABLED=0 go build test/cmd/socksudpclient/socksudpclient.go
|
||||
@@ -379,7 +380,7 @@ test-container-image: test-binary
|
||||
docker build -t mieru_apiclient:${SHORT_SHA} -f test/deploy/apiclient/Dockerfile .
|
||||
docker build -t mieru_proxychain:${SHORT_SHA} -f test/deploy/proxychain/Dockerfile .
|
||||
fi
|
||||
rm -f exampleapiclient mieru mieru2 mita mita2 httpserver sockshttpclient socksudpclient udpserver
|
||||
rm -f exampleapiclient exampleapiserver mieru mieru2 mita mita2 httpserver sockshttpclient socksudpclient udpserver
|
||||
|
||||
# Run docker integration tests.
|
||||
.PHONY: run-container-test
|
||||
|
||||
@@ -30,7 +30,7 @@ import (
|
||||
// EarlyConn implements net.Conn interface.
|
||||
// When the Write() method on the net.Conn is called for the first time,
|
||||
// it performs the initial handshake and writes
|
||||
// the request or response to the peer.
|
||||
// the request or response to the peer within the same network packet.
|
||||
type EarlyConn struct {
|
||||
net.Conn
|
||||
request atomic.Pointer[model.Request]
|
||||
|
||||
@@ -125,6 +125,7 @@ func main() {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Printf("API client is listening to %v\n", l.Addr())
|
||||
|
||||
for {
|
||||
conn, err := l.Accept()
|
||||
if err != nil {
|
||||
@@ -146,32 +147,30 @@ func handleOneSocks5Conn(c client.Client, conn net.Conn) {
|
||||
}
|
||||
|
||||
// Find destination.
|
||||
socks5Header := make([]byte, 3)
|
||||
if _, err := io.ReadFull(conn, socks5Header); err != nil {
|
||||
panic(fmt.Sprintf("Read socks5 header failed: %v", err))
|
||||
}
|
||||
netAddr := model.NetAddrSpec{}
|
||||
var isTCP, isUDP bool
|
||||
if socks5Header[1] == constant.Socks5ConnectCmd {
|
||||
netAddr.Net = "tcp"
|
||||
isTCP = true
|
||||
} else if socks5Header[1] == constant.Socks5UDPAssociateCmd {
|
||||
netAddr.Net = "udp"
|
||||
isUDP = true
|
||||
} else {
|
||||
panic(fmt.Sprintf("Socks5 command %d is invalid", socks5Header[1]))
|
||||
}
|
||||
if err := netAddr.ReadFromSocks5(conn); err != nil {
|
||||
var req model.Request
|
||||
if err := req.ReadFromSocks5(conn); err != nil {
|
||||
panic(fmt.Sprintf("ReadFromSocks5() failed: %v", err))
|
||||
}
|
||||
var isTCP, isUDP bool
|
||||
switch req.Command {
|
||||
case constant.Socks5ConnectCmd:
|
||||
isTCP = true
|
||||
case constant.Socks5UDPAssociateCmd:
|
||||
isUDP = true
|
||||
default:
|
||||
panic(fmt.Sprintf("Invalid socks5 command %d", req.Command))
|
||||
}
|
||||
netAddr, err := req.ToNetAddrSpec()
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("ToNetAddrSpec() failed: %v", err))
|
||||
}
|
||||
if *debug {
|
||||
fmt.Printf("Destination network: %v, address: %v\n", netAddr.Network(), netAddr.String())
|
||||
fmt.Printf("Destination address: %v\n", req.DstAddr)
|
||||
}
|
||||
|
||||
// Dial to proxy server and do handshake.
|
||||
ctx := context.Background()
|
||||
var proxyConn net.Conn
|
||||
var err error
|
||||
proxyConn, err = c.DialContext(ctx, netAddr)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("DialContext() failed: %v", err))
|
||||
|
||||
101
mieru/test/cmd/exampleapiserver/exampleapiserver.go
Normal file
101
mieru/test/cmd/exampleapiserver/exampleapiserver.go
Normal file
@@ -0,0 +1,101 @@
|
||||
// Copyright (C) 2025 mieru authors
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"net"
|
||||
|
||||
"github.com/enfein/mieru/v3/apis/model"
|
||||
"github.com/enfein/mieru/v3/apis/server"
|
||||
"github.com/enfein/mieru/v3/pkg/appctl/appctlpb"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
var (
|
||||
port = flag.Int("port", 0, "mieru API server proxy port to listen")
|
||||
protocol = flag.String("protocol", "TCP", "Proxy transport protocol: TCP or UDP")
|
||||
username = flag.String("username", "", "mieru username")
|
||||
password = flag.String("password", "", "mieru password")
|
||||
useEarlyConn = flag.Bool("use_early_conn", false, "Reply and payload use the same network packet")
|
||||
debug = flag.Bool("debug", false, "Display debug messages")
|
||||
)
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
if *port < 1 || *port > 65535 {
|
||||
panic(fmt.Sprintf("port %d is invalid", *port))
|
||||
}
|
||||
var transportProtocol *appctlpb.TransportProtocol
|
||||
switch *protocol {
|
||||
case "TCP":
|
||||
transportProtocol = appctlpb.TransportProtocol_TCP.Enum()
|
||||
case "UDP":
|
||||
transportProtocol = appctlpb.TransportProtocol_UDP.Enum()
|
||||
default:
|
||||
panic(fmt.Sprintf("Transport protocol %q is invalid", *protocol))
|
||||
}
|
||||
if *username == "" {
|
||||
panic("username is not set")
|
||||
}
|
||||
if *password == "" {
|
||||
panic("password is not set")
|
||||
}
|
||||
|
||||
s := server.NewServer()
|
||||
if err := s.Store(&server.ServerConfig{
|
||||
Config: &appctlpb.ServerConfig{
|
||||
PortBindings: []*appctlpb.PortBinding{
|
||||
{
|
||||
Port: proto.Int32(int32(*port)),
|
||||
Protocol: transportProtocol,
|
||||
},
|
||||
},
|
||||
Users: []*appctlpb.User{
|
||||
{
|
||||
Name: username,
|
||||
Password: password,
|
||||
AllowPrivateIP: proto.Bool(true),
|
||||
AllowLoopbackIP: proto.Bool(true),
|
||||
},
|
||||
},
|
||||
},
|
||||
}); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if _, err := s.Load(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if err := s.Start(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if !s.IsRunning() {
|
||||
panic("server is not running after start")
|
||||
}
|
||||
fmt.Printf("API server is listening to %s port %d\n", *protocol, *port)
|
||||
|
||||
for {
|
||||
conn, req, err := s.Accept()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
handleOneProxyConn(s, conn, req)
|
||||
}
|
||||
}
|
||||
|
||||
func handleOneProxyConn(s server.Server, conn net.Conn, req *model.Request) {}
|
||||
Reference in New Issue
Block a user