diff --git a/HubConnectionOptions.go b/HubConnectionOptions.go index c990aaa..1111788 100644 --- a/HubConnectionOptions.go +++ b/HubConnectionOptions.go @@ -1,11 +1,30 @@ package libnmdc +import ( + "crypto/rand" +) + type HubConnectionOptions struct { Address HubAddress SkipVerifyTLS bool // using a negative verb, because bools default to false SkipAutoReconnect bool // as above Self *UserInfo NickPassword string + AdcPID string // blank: autogenerate +} + +func NewPID() string { + pidBytes := make([]byte, 24) + n, err := rand.Read(pidBytes) + if err != nil { + panic(err) // Insufficient cryptographic randomness + } + + if n != 24 { + panic("Insufficient cryptographic randomness") + } + + return Base32(pidBytes) } func (this *HubConnectionOptions) prepareConnection() *HubConnection { @@ -19,6 +38,10 @@ func (this *HubConnectionOptions) prepareConnection() *HubConnection { this.Self.ClientVersion = "0" } + if this.AdcPID == "" { + this.AdcPID = NewPID() + } + hc := HubConnection{ Hco: this, HubName: DEFAULT_HUB_NAME,