Skip to content

Commit e33e1b5

Browse files
committed
[refactoring] Add more comments to client lib
1 parent 7cf4d35 commit e33e1b5

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

cmd/ssl-auto-ref-client/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func main() {
3333
host := client.DetectHost(*udpAddress)
3434
if host != "" {
3535
log.Print("Detected game-controller host: ", host)
36-
*refBoxAddr = client.SetHost(*refBoxAddr, host)
36+
*refBoxAddr = client.GetConnectionString(*refBoxAddr, host)
3737
}
3838
}
3939

cmd/ssl-team-client/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func main() {
3232
host := client.DetectHost(*udpAddress)
3333
if host != "" {
3434
log.Print("Detected game-controller host: ", host)
35-
*refBoxAddr = client.SetHost(*refBoxAddr, host)
35+
*refBoxAddr = client.GetConnectionString(*refBoxAddr, host)
3636
}
3737
}
3838

internal/app/client/client.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import (
1414
"strings"
1515
)
1616

17+
// DetectHost reads the network address from a multicast message by joining the given multicast group and waiting for
18+
// some data before reading the source IP and returning it.
1719
func DetectHost(address string) string {
1820
addr, err := net.ResolveUDPAddr("udp", address)
1921
if err != nil {
@@ -31,11 +33,14 @@ func DetectHost(address string) string {
3133
return udpAddr.IP.String()
3234
}
3335

34-
func SetHost(address string, host string) string {
36+
// GetConnectionString extracts the port from the given address and constructs a new connection string with the host
37+
// The resulting format is "host:port".
38+
func GetConnectionString(address string, host string) string {
3539
parts := strings.Split(address, ":")
3640
return host + ":" + parts[1]
3741
}
3842

43+
// LoadPrivateKey loads a private RSA key from the given location
3944
func LoadPrivateKey(privateKeyLocation string) *rsa.PrivateKey {
4045
if privateKeyLocation != "" {
4146
privateKey := ReadPrivateKey(privateKeyLocation)
@@ -49,6 +54,7 @@ func LoadPrivateKey(privateKeyLocation string) *rsa.PrivateKey {
4954
return nil
5055
}
5156

57+
// ReadPrivateKey reads a private RSA key from the given location, exiting on errors
5258
func ReadPrivateKey(privateKeyLocation string) *rsa.PrivateKey {
5359
b, err := ioutil.ReadFile(privateKeyLocation)
5460
if err != nil {
@@ -65,6 +71,7 @@ func ReadPrivateKey(privateKeyLocation string) *rsa.PrivateKey {
6571
return privateKey
6672
}
6773

74+
// Sign creates a signature of the given message with the given key
6875
func Sign(privateKey *rsa.PrivateKey, message proto.Message) []byte {
6976
messageBytes, err := proto.Marshal(message)
7077
if err != nil {

0 commit comments

Comments
 (0)