-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
70d30ec
commit 6d952ef
Showing
2 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package main | ||
|
||
func main() { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package proxy | ||
|
||
import ( | ||
"fmt" | ||
"net" | ||
) | ||
|
||
type Sender interface { | ||
Accept() error | ||
} | ||
|
||
// TCPReceiver is responsible for the reading | ||
// incoming tcp connections | ||
type TCPReceiver struct { | ||
localAddr string // localAddr is an address of the proxy server | ||
} | ||
|
||
func NewTCPReceiver(localAddr string) *TCPReceiver { | ||
return &TCPReceiver{ | ||
localAddr: localAddr, | ||
} | ||
} | ||
|
||
func (r *TCPReceiver) Run() error { | ||
lAddr, err := net.ResolveTCPAddr("tcp", r.localAddr) | ||
if err != nil { | ||
return fmt.Errorf("resolving local tcp addr: '%s': %w", r.localAddr, err) | ||
} | ||
|
||
listener, err := net.ListenTCP("tcp", lAddr) | ||
if err != nil { | ||
return fmt.Errorf("creating TCP listener for local address: %w", err) | ||
} | ||
|
||
for { | ||
conn, err := listener.AcceptTCP() | ||
if err != nil { | ||
fmt.Printf("failed to accept TCP connection: %s", err.Error()) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// TCPSender is responsible for the sending | ||
// of the incoming tcp connections to | ||
// desired TCP location. | ||
type TCPSender struct { | ||
// pipes is a map of ipaddr string | ||
// and channel of bytes used to send | ||
// TCP connection to desired location | ||
pipes map[string]any | ||
remoteAddr string | ||
} | ||
|
||
func NewTCPSender(remoteAddr string) *TCPSender { | ||
return &TCPSender{ | ||
pipes: make(map[string]any), | ||
remoteAddr: remoteAddr, | ||
} | ||
} | ||
|
||
func (s *TCPSender) Run() error { | ||
rAddr, err := net.ResolveTCPAddr("tcp", r.remoteAddr) | ||
if err != nil { | ||
return fmt.Errorf("resolving remote tcp addr: '%s': %w", r.remoteAddr, err) | ||
} | ||
} | ||
|
||
type senderConstruct struct { | ||
locationIPAddr *net.IPAddr | ||
} |