diff --git a/relaypool/relaypool.go b/relaypool/relaypool.go index 33d721f..32c83e0 100644 --- a/relaypool/relaypool.go +++ b/relaypool/relaypool.go @@ -40,33 +40,12 @@ type NoticeMessage struct { Relay string } -func (nm *NoticeMessage) UnmarshalJSON(b []byte) error { - var temp []json.RawMessage - if err := json.Unmarshal(b, &temp); err != nil { - return err - } - if len(temp) < 2 { - return errors.New("message is not an array of 2 or more") - } - var tag string - if err := json.Unmarshal(temp[0], &tag); err != nil { - return err - } - if tag != "notice" { - return errors.New("tag is not 'notice'") - } - - if err := json.Unmarshal(temp[1], &nm.Message); err != nil { - return err - } - return nil -} - // New creates a new RelayPool with no relays in it func New() *RelayPool { return &RelayPool{ - Relays: make(map[string]Policy), - websockets: make(map[string]*websocket.Conn), + Relays: make(map[string]Policy), + websockets: make(map[string]*websocket.Conn), + subscriptions: make(map[string]*Subscription), Notices: make(chan *NoticeMessage), } diff --git a/relaypool/subscription.go b/relaypool/subscription.go index f277898..09ac46c 100644 --- a/relaypool/subscription.go +++ b/relaypool/subscription.go @@ -30,7 +30,12 @@ func (subscription Subscription) Unsub() { }) } - close(subscription.Events) + if subscription.Events != nil { + close(subscription.Events) + } + if subscription.UniqueEvents != nil { + close(subscription.UniqueEvents) + } } func (subscription Subscription) Sub(filter *filter.EventFilter) { @@ -46,7 +51,7 @@ func (subscription Subscription) Sub(filter *filter.EventFilter) { }) } - if subscription.started { + if !subscription.started { go subscription.startHandlingUnique() } }