-
Notifications
You must be signed in to change notification settings - Fork 40
/
types.go
executable file
·93 lines (83 loc) · 1.91 KB
/
types.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package ipc
import (
"crypto/cipher"
"net"
"time"
)
// Server - holds the details of the server connection & config.
type Server struct {
name string
listen net.Listener
conn net.Conn
status Status
received chan (*Message)
toWrite chan (*Message)
timeout time.Duration
encryption bool
maxMsgSize int
enc *encryption
unMask bool
}
// Client - holds the details of the client connection and config.
type Client struct {
Name string
conn net.Conn
status Status
timeout float64 //
retryTimer time.Duration // number of seconds before trying to connect again
received chan (*Message)
toWrite chan (*Message)
encryption bool
encryptionReq bool
maxMsgSize int
enc *encryption
}
// Message - contains the received message
type Message struct {
Err error // details of any error
MsgType int // 0 = reserved , -1 is an internal message (disconnection or error etc), all messages recieved will be > 0
Data []byte // message data received
Status string // the status of the connection
}
// Status - Status of the connection
type Status int
const (
// NotConnected - 0
NotConnected Status = iota
// Listening - 1
Listening
// Connecting - 2
Connecting
// Connected - 3
Connected
// ReConnecting - 4
ReConnecting
// Closed - 5
Closed
// Closing - 6
Closing
// Error - 7
Error
// Timeout - 8
Timeout
// Disconnected - 9
Disconnected
)
// ServerConfig - used to pass configuation overrides to ServerStart()
type ServerConfig struct {
MaxMsgSize int
Encryption bool
UnmaskPermissions bool
}
// ClientConfig - used to pass configuation overrides to ClientStart()
type ClientConfig struct {
Timeout float64
RetryTimer time.Duration
Encryption bool
}
// Encryption - encryption settings
type encryption struct {
keyExchange string
encryption string
cipher *cipher.AEAD
}