-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.go
51 lines (44 loc) · 836 Bytes
/
user.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"net"
"encoding/gob"
"log"
"fmt"
"time"
)
type User struct {
Id string
Name string
trackers []*Tracker
conn net.Conn
cryptConn *EncryptedConnection
encoder *gob.Encoder
decoder *gob.Decoder
}
type PeerConn struct {
sideband *ShimConn
initiator bool
udpConn net.Conn
cryptConn *EncryptedConnection
ignorePkts bool
}
func NewUser() *User {
user := &User{}
return user
}
func handleRemoteUdp(pc *PeerConn) {
for {
data := make([]byte, 65535)
_, err := pc.cryptConn.Read(data)
if err != nil {
log.Println("Lost peer connection")
return
} else if !pc.ignorePkts {
log.Println("Received:", string(data))
time.Sleep(1 * time.Second)
send := fmt.Sprintf("Hi %s", time.Now().String())
log.Println("Sent:", send)
pc.cryptConn.Write([]byte(send))
}
}
}