// Balances a message to one of the subscribed nodes. func (o *Overlay) Balance(topic string, msg *proto.Message) error { if err := msg.Encrypt(); err != nil { return err } o.sendBalance(pastry.Resolve(topic), msg) return nil }
// Removes the subscription from topic. func (o *Overlay) Unsubscribe(topic string) error { // Resolve the topic id id := pastry.Resolve(topic) sid := id.String() // Remove the topic name mapping o.lock.Lock() delete(o.names, sid) o.lock.Unlock() // Remove the scribe subscription return o.handleUnsubscribe(o.pastry.Self(), id) }
// Subscribes to the specified scribe topic. func (o *Overlay) Subscribe(topic string) error { // Resolve the topic id id := pastry.Resolve(topic) sid := id.String() // Make sure we can map the id back to the textual name o.lock.RLock() _, ok := o.names[sid] o.lock.RUnlock() if !ok { o.lock.Lock() o.names[sid] = topic o.lock.Unlock() } // Subscribe the local node to the topic return o.handleSubscribe(o.pastry.Self(), id) }