Skip to content

Commit 6415080

Browse files
committed
add description and external ip printing
1 parent 676f839 commit 6415080

File tree

5 files changed

+73
-12
lines changed

5 files changed

+73
-12
lines changed

README.md

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,41 @@
11
# proxypunch
22

3-
To run:
4-
Make sure to setup your Go environment, and to add $GOPATH/bin to your PATH, then:
5-
```
6-
go get github.com/delthas/proxypunch
7-
go install github.com/delthas/proxypunch
8-
proxypunch
9-
```
3+
**This program lets you host & connect to friends to play peer-to-peer games without having to open or redirect any port.**
4+
5+
*Technical details: proxypunch creates a user-friendly UDP proxy/tunnel between two peers by hole punching the user's NAT with a custom STUN-like server which additionally "matchmakes" users based on their internal port rather than their NAT-ed port.*
6+
7+
## How to use
8+
9+
- Download the [latest version for Windows 64 bits](https://github.com/delthas/proxypunch/releases/latest/download/proxypunch.win64.exe) (for other OS check the [latest release page](https://github.com/delthas/proxypunch/releases/latest/))
10+
- Simply double-click the downloaded executable file to run it; there is no setup or anything so put the file somewhere you'll remember
11+
- If a Windows Security Alert popup appears, check all checkboxes and click on "Allow access"
12+
- If prompted for an update, press `Enter` to accept the update; proxypunch will update and restart automatically
13+
- Choose between **server** (hosting) and **client** (connecting to a host) by typing `s` or `c`, then pressing `Enter`
14+
- Instructions continue below depending on your choice
15+
16+
##### Server / Hosting
17+
18+
- When prompted for a port, choose any port (if you're not sure, choose any randon number between 10000 and 60000), type it and press `Enter`
19+
- In your game, start your server / start hosting on the port you chose
20+
- Ask your peer to connect to the shown host and port, **the peer must connect with proxypunch as explained below, not directly**
21+
- Wait for the peer to connect, then play & profit
22+
- When you're done playing with this peer, stop hosting, and close the proxypunch window (start it again and repeat the process to play with someone else)
23+
- Next time you run proxypunch, you can simply press `Enter` to use the same settings as last time you connected
24+
25+
##### Client / Connecting to a host
26+
27+
- Wait for the person hosting to send you a host and port to connect to
28+
- Enter the host and port when prompted to by typing it and pressing `Enter`
29+
- In your game, connect to the shown host and port (**not the host and port your peer gave you**)
30+
- Profit & play
31+
- When you're done playing with this peer, disconnect, and close the proxypunch window (start it again and repeat the process to play with someone else)
32+
- Next time you run proxypunch, you can simply press `Enter` to use the same settings as last time you connected
33+
34+
##### Troubleshooting
35+
36+
- If you experience any issue when restarting proxypunch to play with someone else, try to use a different port every time your run proxypunch
37+
- If you have any other issue or feedback, either contact me on Discord at `cc#6439` or [open an issue on Github](https://github.com/delthas/proxypunch/issues/new)
38+
39+
## Advanced usage
40+
41+
- Command-line flags are available for quick/unattended start, run `proxypunch -help` to review the flags

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module github.com/delthas/proxypunch
2+
3+
require gopkg.in/yaml.v2 v2.2.2

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
2+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
3+
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
4+
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

main.go

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func client(host string, port int) {
4848
defer c.Close()
4949

5050
localPort := c.LocalAddr().(*net.UDPAddr).Port
51-
fmt.Println("Listening, connect to 127.0.0.1:" + strconv.Itoa(localPort))
51+
fmt.Println("Listening, connect to 127.0.0.1 on port " + strconv.Itoa(localPort))
5252

5353
relayAddr, err := net.ResolveUDPAddr("udp4", relayHost)
5454
if err != nil {
@@ -109,6 +109,7 @@ func client(host string, port int) {
109109
}()
110110
defer close(chPunch)
111111

112+
foundPeer := false
112113
var localAddr net.UDPAddr
113114
for {
114115
n, addr, err := c.ReadFromUDP(buffer[1:])
@@ -124,6 +125,10 @@ func client(host string, port int) {
124125
continue
125126
}
126127
if addr.IP.Equal(remoteAddr.IP) && addr.Port == remoteAddr.Port {
128+
if !foundPeer {
129+
foundPeer = true
130+
fmt.Println("Connected to peer")
131+
}
127132
if n != 0 && localAddr.Port != 0 && buffer[1] == 0xCC {
128133
c.WriteToUDP(buffer[2:n+1], &localAddr)
129134
}
@@ -142,7 +147,8 @@ func server(port int) {
142147
}
143148
defer c.Close()
144149

145-
fmt.Println("Listening, host at " + strconv.Itoa(port))
150+
fmt.Println("Listening, start hosting on port " + strconv.Itoa(port))
151+
fmt.Println("Connecting...")
146152

147153
localAddr := &net.UDPAddr{
148154
IP: net.IPv4(127, 0, 0, 1),
@@ -172,6 +178,7 @@ func server(port int) {
172178
var remoteAddr net.UDPAddr
173179
buffer := make([]byte, 4096)
174180

181+
receivedIp := false
175182
for {
176183
n, addr, err := c.ReadFromUDP(buffer)
177184
if err != nil {
@@ -181,6 +188,14 @@ func server(port int) {
181188
if !addr.IP.Equal(relayAddr.IP) || addr.Port != relayAddr.Port {
182189
continue
183190
}
191+
if n == 4 {
192+
if !receivedIp {
193+
receivedIp = true
194+
ip := net.IP(buffer[:4])
195+
fmt.Println("Connected. Ask your peer to connect to " + ip.String() + " on port " + strconv.Itoa(port) + " with proxypunch")
196+
}
197+
continue
198+
}
184199
if n != 6 {
185200
fmt.Fprintln(os.Stderr, "Error received packet of wrong size from relay. (size:"+strconv.Itoa(n)+")")
186201
continue
@@ -209,6 +224,7 @@ func server(port int) {
209224
}()
210225
defer close(chPunch)
211226

227+
foundPeer := false
212228
for {
213229
n, addr, err := c.ReadFromUDP(buffer[1:])
214230
if err != nil {
@@ -223,6 +239,10 @@ func server(port int) {
223239
continue
224240
}
225241
if addr.IP.Equal(remoteAddr.IP) && addr.Port == remoteAddr.Port {
242+
if !foundPeer {
243+
foundPeer = true
244+
fmt.Println("Connected to peer")
245+
}
226246
if n != 0 && buffer[1] == 0xCC {
227247
c.WriteToUDP(buffer[2:n+1], localAddr)
228248
}
@@ -370,7 +390,7 @@ func main() {
370390
if ProgramVersion == "" {
371391
ProgramVersion = "[Custom Build]"
372392
}
373-
fmt.Println("ProxyPunch " + ProgramVersion + " by delthas")
393+
fmt.Println("proxypunch " + ProgramVersion + " by delthas")
374394
fmt.Println()
375395

376396
if runtime.GOOS == "windows" {

proxypunch-server/main.go renamed to proxypunch-relay/main.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ type serverValue struct {
3232
}
3333

3434
func main() {
35-
fmt.Println("ProxyPunch Server v" + version)
35+
fmt.Println("proxypunch relay v" + version)
3636
fmt.Println()
3737

3838
var port int
39-
flag.IntVar(&port, "port", defaultPort, "server listen port")
39+
flag.IntVar(&port, "port", defaultPort, "relay listen port")
4040
flag.Parse()
4141

4242
c, err := net.ListenUDP("udp4", &net.UDPAddr{
@@ -94,6 +94,8 @@ func main() {
9494
if val, ok := clients[key]; ok {
9595
serverPayload := append([]byte{byte(val.natPort >> 8), byte(val.natPort)}, val.localIp[:]...)
9696
c.WriteToUDP(serverPayload, addr)
97+
} else {
98+
c.WriteToUDP(senderIp[:], addr)
9799
}
98100
} else if n == 6 {
99101
var ip [4]byte

0 commit comments

Comments
 (0)