@@ -155,6 +155,7 @@ func (c cassVersion) nodeUpDelay() time.Duration {
155155 return 10 * time .Second
156156}
157157
158+ // HostInfo holds information about the host (e.g. addresses and state).
158159type HostInfo struct {
159160 // TODO(zariel): reduce locking maybe, not all values will change, but to ensure
160161 // that we are thread safe use a mutex to access all fields.
@@ -181,6 +182,7 @@ type HostInfo struct {
181182 tokens []string
182183}
183184
185+ // Equal returns true if hosts are equal of if connect addresses of the hosts are equal.
184186func (h * HostInfo ) Equal (host * HostInfo ) bool {
185187 if h == host {
186188 // prevent rlock reentry
@@ -190,6 +192,7 @@ func (h *HostInfo) Equal(host *HostInfo) bool {
190192 return h .ConnectAddress ().Equal (host .ConnectAddress ())
191193}
192194
195+ // Peer returns hosts peer.
193196func (h * HostInfo ) Peer () net.IP {
194197 h .mu .RLock ()
195198 defer h .mu .RUnlock ()
@@ -260,92 +263,107 @@ func (h *HostInfo) SetConnectAddress(address net.IP) *HostInfo {
260263 return h
261264}
262265
266+ // BroadcastAddress returns the broadcast address of the host.
263267func (h * HostInfo ) BroadcastAddress () net.IP {
264268 h .mu .RLock ()
265269 defer h .mu .RUnlock ()
266270 return h .broadcastAddress
267271}
268272
273+ // ListenAddress returns the address on which a host listens for incoming connections.
269274func (h * HostInfo ) ListenAddress () net.IP {
270275 h .mu .RLock ()
271276 defer h .mu .RUnlock ()
272277 return h .listenAddress
273278}
274279
280+ // RPCAddress returns address on which host listens for RPC requests.
275281func (h * HostInfo ) RPCAddress () net.IP {
276282 h .mu .RLock ()
277283 defer h .mu .RUnlock ()
278284 return h .rpcAddress
279285}
280286
287+ // PreferredIP returns the preferred IP of the host.
281288func (h * HostInfo ) PreferredIP () net.IP {
282289 h .mu .RLock ()
283290 defer h .mu .RUnlock ()
284291 return h .preferredIP
285292}
286293
294+ // DataCenter returns the name of the host data center.
287295func (h * HostInfo ) DataCenter () string {
288296 h .mu .RLock ()
289297 dc := h .dataCenter
290298 h .mu .RUnlock ()
291299 return dc
292300}
293301
302+ // Rack returns the name of the host rack.
294303func (h * HostInfo ) Rack () string {
295304 h .mu .RLock ()
296305 rack := h .rack
297306 h .mu .RUnlock ()
298307 return rack
299308}
300309
310+ // HostID returns the host ID.
301311func (h * HostInfo ) HostID () string {
302312 h .mu .RLock ()
303313 defer h .mu .RUnlock ()
304314 return h .hostId
305315}
306316
317+ // SetHostID sets the host ID.
307318func (h * HostInfo ) SetHostID (hostID string ) {
308319 h .mu .Lock ()
309320 defer h .mu .Unlock ()
310321 h .hostId = hostID
311322}
312323
324+ // WorkLoad returns the current workload of the host.
313325func (h * HostInfo ) WorkLoad () string {
314326 h .mu .RLock ()
315327 defer h .mu .RUnlock ()
316328 return h .workload
317329}
318330
331+ // Graph returns true if graph mode is enabled for the DSE.
319332func (h * HostInfo ) Graph () bool {
320333 h .mu .RLock ()
321334 defer h .mu .RUnlock ()
322335 return h .graph
323336}
324337
338+ // DSEVersion returns the version of DSE instance.
325339func (h * HostInfo ) DSEVersion () string {
326340 h .mu .RLock ()
327341 defer h .mu .RUnlock ()
328342 return h .dseVersion
329343}
330344
345+ // Partitioner returns the partitioner kind.
331346func (h * HostInfo ) Partitioner () string {
332347 h .mu .RLock ()
333348 defer h .mu .RUnlock ()
334349 return h .partitioner
335350}
336351
352+ // ClusterName returns name of the cluster.
337353func (h * HostInfo ) ClusterName () string {
338354 h .mu .RLock ()
339355 defer h .mu .RUnlock ()
340356 return h .clusterName
341357}
342358
359+ // Version returns version of the Cassandra instance.
343360func (h * HostInfo ) Version () cassVersion {
344361 h .mu .RLock ()
345362 defer h .mu .RUnlock ()
346363 return h .version
347364}
348365
366+ // State returns state of the node.
349367func (h * HostInfo ) State () nodeState {
350368 h .mu .RLock ()
351369 defer h .mu .RUnlock ()
@@ -359,12 +377,14 @@ func (h *HostInfo) setState(state nodeState) *HostInfo {
359377 return h
360378}
361379
380+ // Tokens returns slice of tokens.
362381func (h * HostInfo ) Tokens () []string {
363382 h .mu .RLock ()
364383 defer h .mu .RUnlock ()
365384 return h .tokens
366385}
367386
387+ // Port returns port which used for the connection.
368388func (h * HostInfo ) Port () int {
369389 h .mu .RLock ()
370390 defer h .mu .RUnlock ()
@@ -433,10 +453,13 @@ func (h *HostInfo) update(from *HostInfo) {
433453 }
434454}
435455
456+ // IsUp return true if the host is not nil and if the host state is node NodeUp.
436457func (h * HostInfo ) IsUp () bool {
437458 return h != nil && h .State () == NodeUp
438459}
439460
461+ // HostnameAndPort returns a network address of the form "host:port".
462+ // If host contains a colon - "[host]:port" will be returned.
440463func (h * HostInfo ) HostnameAndPort () string {
441464 h .mu .Lock ()
442465 defer h .mu .Unlock ()
@@ -447,6 +470,8 @@ func (h *HostInfo) HostnameAndPort() string {
447470 return net .JoinHostPort (h .hostname , strconv .Itoa (h .port ))
448471}
449472
473+ // ConnectAddressAndPort returns a network address of the form "host:port".
474+ // If connect address contains a colon - "[host]:port" will be returned.
450475func (h * HostInfo ) ConnectAddressAndPort () string {
451476 h .mu .Lock ()
452477 defer h .mu .Unlock ()
0 commit comments