rename request to packet

This commit is contained in:
xvzc 2022-01-08 15:35:32 +09:00
parent 539d256146
commit 11ed1fd681
5 changed files with 13 additions and 12 deletions

View File

@ -1,4 +1,4 @@
package request package packet
import ( import (
"strings" "strings"
@ -29,8 +29,8 @@ func (r *HttpRequest) IsValidMethod() bool {
return false return false
} }
func (r *HttpRequest) ToChunks() { func (r *HttpRequest) IsConnectMethod() bool {
return r.Method == "CONNECT"
} }
func parse(raw *[]byte) (string, string, string) { func parse(raw *[]byte) (string, string, string) {

View File

@ -1,4 +1,4 @@
package request package packet
type HttpsRequest struct { type HttpsRequest struct {
Raw *[]byte Raw *[]byte

View File

@ -4,11 +4,11 @@ import (
"fmt" "fmt"
"net" "net"
"github.com/xvzc/SpoofDPI/request" "github.com/xvzc/SpoofDPI/packet"
"github.com/xvzc/SpoofDPI/util" "github.com/xvzc/SpoofDPI/util"
) )
func HandleHttp(clientConn net.Conn, ip string, r *request.HttpRequest) { func HandleHttp(clientConn net.Conn, ip string, p *packet.HttpRequest) {
remoteConn, err := net.Dial("tcp", ip+":80") // create connection to server remoteConn, err := net.Dial("tcp", ip+":80") // create connection to server
if err != nil { if err != nil {
util.Debug(err) util.Debug(err)
@ -21,7 +21,7 @@ func HandleHttp(clientConn net.Conn, ip string, r *request.HttpRequest) {
go Serve(remoteConn, clientConn, "HTTP") go Serve(remoteConn, clientConn, "HTTP")
util.Debug("[HTTP] Sending request to the server") util.Debug("[HTTP] Sending request to the server")
fmt.Fprintf(remoteConn, string(*r.Raw)) fmt.Fprintf(remoteConn, string(*p.Raw))
Serve(clientConn, remoteConn, "HTTP") Serve(clientConn, remoteConn, "HTTP")
} }

View File

@ -4,10 +4,11 @@ import (
"fmt" "fmt"
"net" "net"
"github.com/xvzc/SpoofDPI/packet"
"github.com/xvzc/SpoofDPI/util" "github.com/xvzc/SpoofDPI/util"
) )
func HandleHttps(clientConn net.Conn, ip string) { func HandleHttps(clientConn net.Conn, ip string, r *packet.HttpRequest) {
// Create a connection to the requested server // Create a connection to the requested server
remoteConn, err := net.Dial("tcp", ip+":443") remoteConn, err := net.Dial("tcp", ip+":443")
if err != nil { if err != nil {

View File

@ -6,7 +6,7 @@ import (
"os" "os"
"github.com/xvzc/SpoofDPI/config" "github.com/xvzc/SpoofDPI/config"
"github.com/xvzc/SpoofDPI/request" "github.com/xvzc/SpoofDPI/packet"
"github.com/xvzc/SpoofDPI/util" "github.com/xvzc/SpoofDPI/util"
) )
@ -38,7 +38,7 @@ func Start() {
util.Debug("Client sent data: ", len(b)) util.Debug("Client sent data: ", len(b))
r := request.NewHttpRequest(&b) r := packet.NewHttpRequest(&b)
util.Debug("Request: \n" + string(*r.Raw)) util.Debug("Request: \n" + string(*r.Raw))
if !r.IsValidMethod() { if !r.IsValidMethod() {
@ -55,9 +55,9 @@ func Start() {
util.Debug("ip: " + ip) util.Debug("ip: " + ip)
if r.Method == "CONNECT" { if r.IsConnectMethod() {
util.Debug("HTTPS Requested") util.Debug("HTTPS Requested")
HandleHttps(clientConn, ip) HandleHttps(clientConn, ip, &r)
} else { } else {
util.Debug("HTTP Requested.") util.Debug("HTTP Requested.")
HandleHttp(clientConn, ip, &r) HandleHttp(clientConn, ip, &r)