Advertise and update node names on cluster config exchange

Closes #244
This commit is contained in:
Audrius Butkevicius
2014-08-14 23:15:26 +01:00
parent bc885f1d08
commit e8a679c280
7 changed files with 98 additions and 13 deletions

View File

@@ -68,6 +68,7 @@ type Model struct {
cfg *config.Configuration
db *leveldb.DB
nodeName string
clientName string
clientVersion string
@@ -101,11 +102,12 @@ var (
// NewModel creates and starts a new model. The model starts in read-only mode,
// where it sends index information to connected peers and responds to requests
// for file data without altering the local repository in any way.
func NewModel(indexDir string, cfg *config.Configuration, clientName, clientVersion string, db *leveldb.DB) *Model {
func NewModel(indexDir string, cfg *config.Configuration, nodeName, clientName, clientVersion string, db *leveldb.DB) *Model {
m := &Model{
indexDir: indexDir,
cfg: cfg,
db: db,
nodeName: nodeName,
clientName: clientName,
clientVersion: clientVersion,
repoCfgs: make(map[string]config.RepositoryConfiguration),
@@ -406,6 +408,14 @@ func (m *Model) ClusterConfig(nodeID protocol.NodeID, config protocol.ClusterCon
} else {
m.nodeVer[nodeID] = config.ClientName + " " + config.ClientVersion
}
name := config.GetOption("name")
if name != "" {
node := m.cfg.GetNodeConfiguration(nodeID)
if node != nil && node.Name == "" {
l.Infof("Node %s is called %q", nodeID, name)
node.Name = name
}
}
m.pmut.Unlock()
l.Infof(`Node %s client is "%s %s"`, nodeID, config.ClientName, config.ClientVersion)
@@ -838,6 +848,12 @@ func (m *Model) clusterConfig(node protocol.NodeID) protocol.ClusterConfigMessag
cm := protocol.ClusterConfigMessage{
ClientName: m.clientName,
ClientVersion: m.clientVersion,
Options: []protocol.Option{
{
Key: "name",
Value: m.nodeName,
},
},
}
m.rmut.RLock()