diff --git a/broker.go b/broker.go index c6a83265c7..cd3ae8e635 100644 --- a/broker.go +++ b/broker.go @@ -61,6 +61,7 @@ type Sub struct { // Broker represents a message broker. type Broker struct { site *Site + editable bool clients map[string]map[*Client]interface{} // route => client-set publish chan Pub subscribe chan Sub @@ -70,9 +71,10 @@ type Broker struct { appsMux sync.RWMutex // mutex for tracking apps } -func newBroker(site *Site) *Broker { +func newBroker(site *Site, editable bool) *Broker { return &Broker{ site, + editable, make(map[string]map[*Client]interface{}), make(chan Pub, 1024), // TODO tune make(chan Sub, 1024), // TODO tune @@ -146,6 +148,15 @@ func parseMsg(s []byte) Msg { // patch broadcasts changes to clients and patches site data. func (b *Broker) patch(route string, data []byte) { b.publish <- Pub{route, data} + + // Skip writes if the route belongs to an app set to unicast mode, and -editable is not set. + if !b.editable { + app := b.getApp(route) + if app != nil && app.mode == unicastMode { + return + } + } + // Write AOF entry with patch marker "*" as-is to log file. // FIXME bufio.Scanner.Scan() is not reliable if line length > 65536 chars, // so reading back in is unreliable. diff --git a/pkg/keychain/keychain.go b/pkg/keychain/keychain.go index d93bbb0819..4cc6a76341 100644 --- a/pkg/keychain/keychain.go +++ b/pkg/keychain/keychain.go @@ -134,6 +134,9 @@ func (kc *Keychain) Len() int { } func newLruCache(size int) (*lru.Cache, error) { + if size < 8 { + size = 8 + } cache, err := lru.New(size) if err != nil { return nil, fmt.Errorf("failed creating keychain LRU cache: %s", err) diff --git a/server.go b/server.go index e9f869ecd6..55137085f0 100644 --- a/server.go +++ b/server.go @@ -53,7 +53,7 @@ func Run(conf ServerConf) { initSite(site, conf.Init) } - broker := newBroker(site) + broker := newBroker(site, conf.Editable) go broker.run() if conf.Debug {