@@ -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.
1719func 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
3944func 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
5258func 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
6875func Sign (privateKey * rsa.PrivateKey , message proto.Message ) []byte {
6976 messageBytes , err := proto .Marshal (message )
7077 if err != nil {
0 commit comments