-
Notifications
You must be signed in to change notification settings - Fork 13
/
main.go
45 lines (40 loc) · 935 Bytes
/
main.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
package main
import (
"fmt"
"net"
"os"
)
const (
SERVER_RECV_PORT = 1067
CLIENT_TIMEOUT = 3 // seconds
KEY_REQUEST_TEXT = `Key, plz!`
UDP_MSG_SIZE = 4096 // the effective max key size
KEY_DATA_ENV_VAR = `DOCKER-SSH-KEY`
)
// Package version & timestamp - interpolated by goxc
const VERSION = "0.5.2"
const SOURCE_DATE = "2017-10-13T16:40:18-07:00"
func main() {
config := newConfig()
if config.Server {
server(config)
} else {
client(config)
}
}
// Opens a UDP read socket at UDPAddr, and returns the connection object.
// mode should be "r" or "w"
// Exits and prints the error if one occurs.
func openUDPSocket(mode string, addr net.UDPAddr) (socket *net.UDPConn) {
var err error
if mode == `w` {
socket, err = net.DialUDP("udp4", nil, &addr)
} else {
socket, err = net.ListenUDP("udp4", &addr)
}
if err != nil {
fmt.Println("Error opening receive port: ", err)
os.Exit(0)
}
return socket
}