From a3963f196a0cb83213784873590e7ab2e1c56cc1 Mon Sep 17 00:00:00 2001 From: mappu Date: Sun, 26 Nov 2017 13:29:44 +1300 Subject: [PATCH] adc: PID management --HG-- branch : adc --- HubConnectionOptions.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) 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,