Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve logging #8

Merged
merged 1 commit into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ build:

.PHONY: docker
docker:
docker build -f docker/Dockerfile -t obfsproxy:latest .
docker build -f docker/Dockerfile -t obfsproxy .

.PHONY: test
test:
Expand Down
15 changes: 13 additions & 2 deletions cmd/obfsproxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,24 @@ func main() {
Short: "A simple obfuscating proxy",
RunE: func(cmd *cobra.Command, args []string) error {
// Validate flags
if key == "" {
return fmt.Errorf("key is required")
}

if isServer && isClient {
return fmt.Errorf("cannot specify both server (-s) and client (-c) modes")
}
if !isServer && !isClient {
isClient = true
}

if isClient {
fmt.Println("Running in client mode")
}
if isServer {
fmt.Println("Running in server mode")
}

// Calculate seed from key
var seed uint64
for _, ch := range key {
Expand Down Expand Up @@ -74,8 +85,8 @@ func main() {
rootCmd.Flags().StringVarP(&targetAddr, "target", "t", "localhost:80", "Address to forward to")
rootCmd.Flags().BoolVarP(&isServer, "server", "s", false, "Run in server mode")
rootCmd.Flags().BoolVarP(&isClient, "client", "c", false, "Run in client mode")
rootCmd.Flags().StringVarP(&key, "key", "k", "", "Encryption key (required)")
rootCmd.Flags().IntVarP(&redundancy, "redundancy", "r", 50, "Redundancy level (0-1000)")
rootCmd.Flags().StringVarP(&key, "key", "k", "", "Obfuscation key (required)")
rootCmd.Flags().IntVarP(&redundancy, "redundancy", "r", 20, "Redundancy level (0-1000)")

if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
Expand Down
28 changes: 24 additions & 4 deletions pkg/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"io"
"log"
"net"
"sync"

"github.com/askolesov/obfsproxy/pkg/codec"
)
Expand Down Expand Up @@ -40,6 +41,7 @@ func (p *Proxy) Start() error {
log.Printf("Error accepting connection: %v", err)
continue
}
log.Printf("Accepted connection from %s", clientConn.RemoteAddr())
go p.handleConnection(clientConn)
}
}
Expand All @@ -52,15 +54,33 @@ func (p *Proxy) handleConnection(clientConn net.Conn) {
log.Printf("Error connecting to target: %v", err)
return
}
log.Printf("Connected to target %s", targetConn.RemoteAddr())
defer targetConn.Close()

wg := sync.WaitGroup{}
wg.Add(2)

if p.IsServer {
go p.proxy(clientConn, targetConn, p.Codec.NewDecoder())
p.proxy(targetConn, clientConn, p.Codec.NewEncoder())
go func() {
defer wg.Done()
p.proxy(clientConn, targetConn, p.Codec.NewDecoder())
}()
go func() {
defer wg.Done()
p.proxy(targetConn, clientConn, p.Codec.NewEncoder())
}()
} else {
go p.proxy(clientConn, targetConn, p.Codec.NewEncoder())
p.proxy(targetConn, clientConn, p.Codec.NewDecoder())
go func() {
defer wg.Done()
p.proxy(clientConn, targetConn, p.Codec.NewEncoder())
}()
go func() {
defer wg.Done()
p.proxy(targetConn, clientConn, p.Codec.NewDecoder())
}()
}

wg.Wait()
}

func (p *Proxy) proxy(src, dst net.Conn, t codec.Transformer) {
Expand Down
Loading