Added Hostname Property to Configuration
I added a "hostname" property to a node's configuration file. Its value defaults to the hostname provided by the OS, but can be modified to anything beside an empty string in the config file. The "hostname" was added to the output of the "id" call. Thus, peer hostnames are available when listing peers.
This commit is contained in:
parent
cb5012c53b
commit
c6c8512a27
|
@ -239,6 +239,7 @@ type ID struct {
|
|||
RPCProtocolVersion protocol.ID
|
||||
Error string
|
||||
IPFS IPFSID
|
||||
Hostname string
|
||||
//PublicKey crypto.PubKey
|
||||
}
|
||||
|
||||
|
@ -253,6 +254,7 @@ type IDSerial struct {
|
|||
RPCProtocolVersion string `json:"rpc_protocol_version"`
|
||||
Error string `json:"error"`
|
||||
IPFS IPFSIDSerial `json:"ipfs"`
|
||||
Hostname string `json:"hostname"`
|
||||
//PublicKey []byte
|
||||
}
|
||||
|
||||
|
@ -279,6 +281,7 @@ func (id ID) ToSerial() IDSerial {
|
|||
RPCProtocolVersion: string(id.RPCProtocolVersion),
|
||||
Error: id.Error,
|
||||
IPFS: id.IPFS.ToSerial(),
|
||||
Hostname: id.Hostname,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -306,6 +309,7 @@ func (ids IDSerial) ToID() ID {
|
|||
id.RPCProtocolVersion = protocol.ID(ids.RPCProtocolVersion)
|
||||
id.Error = ids.Error
|
||||
id.IPFS = ids.IPFS.ToIPFSID()
|
||||
id.Hostname = ids.Hostname
|
||||
return id
|
||||
}
|
||||
|
||||
|
|
|
@ -599,6 +599,7 @@ func (c *Cluster) ID() api.ID {
|
|||
Commit: Commit,
|
||||
RPCProtocolVersion: RPCProtocol,
|
||||
IPFS: ipfsID,
|
||||
Hostname: c.config.Hostname,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
|
@ -44,6 +45,9 @@ type Config struct {
|
|||
ID peer.ID
|
||||
PrivateKey crypto.PrivKey
|
||||
|
||||
// User-defined hostname for use as human-readable identifier.
|
||||
Hostname string
|
||||
|
||||
// Cluster secret for private network. Peers will be in the same cluster if and
|
||||
// only if they have the same ClusterSecret. The cluster secret must be exactly
|
||||
// 64 characters and contain only hexadecimal characters (`[0-9a-f]`).
|
||||
|
@ -100,6 +104,7 @@ type Config struct {
|
|||
// like strings, and key names aim to be self-explanatory for the user.
|
||||
type configJSON struct {
|
||||
ID string `json:"id"`
|
||||
Hostname string `json:"hostname"`
|
||||
PrivateKey string `json:"private_key"`
|
||||
Secret string `json:"secret"`
|
||||
Peers []string `json:"peers"`
|
||||
|
@ -194,6 +199,9 @@ func (cfg *Config) Validate() error {
|
|||
|
||||
// this just sets non-generated defaults
|
||||
func (cfg *Config) setDefaults() {
|
||||
hostname, _ := os.Hostname()
|
||||
cfg.Hostname = hostname
|
||||
|
||||
addr, _ := ma.NewMultiaddr(DefaultListenAddr)
|
||||
cfg.ListenAddr = addr
|
||||
cfg.Peers = []ma.Multiaddr{}
|
||||
|
@ -226,6 +234,10 @@ func (cfg *Config) LoadJSON(raw []byte) error {
|
|||
}
|
||||
cfg.ID = id
|
||||
|
||||
if jcfg.Hostname != "" {
|
||||
cfg.Hostname = jcfg.Hostname
|
||||
}
|
||||
|
||||
pkb, err := base64.StdEncoding.DecodeString(jcfg.PrivateKey)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error decoding private_key: %s", err)
|
||||
|
@ -330,6 +342,7 @@ func (cfg *Config) ToJSON() (raw []byte, err error) {
|
|||
|
||||
// Set all configuration fields
|
||||
jcfg.ID = cfg.ID.Pretty()
|
||||
jcfg.Hostname = cfg.Hostname
|
||||
jcfg.PrivateKey = pKey
|
||||
jcfg.Secret = EncodeClusterSecret(cfg.Secret)
|
||||
jcfg.Peers = clusterPeers
|
||||
|
|
|
@ -81,7 +81,7 @@ func textFormatPrintIDSerial(obj *api.IDSerial) {
|
|||
return
|
||||
}
|
||||
|
||||
fmt.Printf("%s | Sees %d other peers\n", obj.ID, len(obj.ClusterPeers)-1)
|
||||
fmt.Printf("%s | '%s' | Sees %d other peers\n", obj.ID, obj.Hostname, len(obj.ClusterPeers)-1)
|
||||
addrs := make(sort.StringSlice, 0, len(obj.Addresses))
|
||||
for _, a := range obj.Addresses {
|
||||
addrs = append(addrs, string(a))
|
||||
|
|
Loading…
Reference in New Issue
Block a user