@@ -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.
@@ -193,6 +194,7 @@ func newHostInfo(addr net.IP, port int) (*HostInfo, error) {
193194 return host , nil
194195}
195196
197+ // Equal returns true if hosts are equal of if connect addresses of the hosts are equal.
196198func (h * HostInfo ) Equal (host * HostInfo ) bool {
197199 if h == host {
198200 // prevent rlock reentry
@@ -202,6 +204,7 @@ func (h *HostInfo) Equal(host *HostInfo) bool {
202204 return h .ConnectAddress ().Equal (host .ConnectAddress ())
203205}
204206
207+ // Peer returns hosts peer.
205208func (h * HostInfo ) Peer () net.IP {
206209 h .mu .RLock ()
207210 defer h .mu .RUnlock ()
@@ -259,92 +262,107 @@ func (h *HostInfo) ConnectAddress() net.IP {
259262 return addr
260263}
261264
265+ // BroadcastAddress returns the broadcast address of the host.
262266func (h * HostInfo ) BroadcastAddress () net.IP {
263267 h .mu .RLock ()
264268 defer h .mu .RUnlock ()
265269 return h .broadcastAddress
266270}
267271
272+ // ListenAddress returns the address on which a host listens for incoming connections.
268273func (h * HostInfo ) ListenAddress () net.IP {
269274 h .mu .RLock ()
270275 defer h .mu .RUnlock ()
271276 return h .listenAddress
272277}
273278
279+ // RPCAddress returns address on which host listens for RPC requests.
274280func (h * HostInfo ) RPCAddress () net.IP {
275281 h .mu .RLock ()
276282 defer h .mu .RUnlock ()
277283 return h .rpcAddress
278284}
279285
286+ // PreferredIP returns the preferred IP of the host.
280287func (h * HostInfo ) PreferredIP () net.IP {
281288 h .mu .RLock ()
282289 defer h .mu .RUnlock ()
283290 return h .preferredIP
284291}
285292
293+ // DataCenter returns the name of the host data center.
286294func (h * HostInfo ) DataCenter () string {
287295 h .mu .RLock ()
288296 dc := h .dataCenter
289297 h .mu .RUnlock ()
290298 return dc
291299}
292300
301+ // Rack returns the name of the host rack.
293302func (h * HostInfo ) Rack () string {
294303 h .mu .RLock ()
295304 rack := h .rack
296305 h .mu .RUnlock ()
297306 return rack
298307}
299308
309+ // HostID returns the host ID.
300310func (h * HostInfo ) HostID () string {
301311 h .mu .RLock ()
302312 defer h .mu .RUnlock ()
303313 return h .hostId
304314}
305315
316+ // SetHostID sets the host ID.
306317func (h * HostInfo ) SetHostID (hostID string ) {
307318 h .mu .Lock ()
308319 defer h .mu .Unlock ()
309320 h .hostId = hostID
310321}
311322
323+ // WorkLoad returns the current workload of the host.
312324func (h * HostInfo ) WorkLoad () string {
313325 h .mu .RLock ()
314326 defer h .mu .RUnlock ()
315327 return h .workload
316328}
317329
330+ // Graph returns true if graph mode is enabled for the DSE.
318331func (h * HostInfo ) Graph () bool {
319332 h .mu .RLock ()
320333 defer h .mu .RUnlock ()
321334 return h .graph
322335}
323336
337+ // DSEVersion returns the version of DSE instance.
324338func (h * HostInfo ) DSEVersion () string {
325339 h .mu .RLock ()
326340 defer h .mu .RUnlock ()
327341 return h .dseVersion
328342}
329343
344+ // Partitioner returns the partitioner kind.
330345func (h * HostInfo ) Partitioner () string {
331346 h .mu .RLock ()
332347 defer h .mu .RUnlock ()
333348 return h .partitioner
334349}
335350
351+ // ClusterName returns name of the cluster.
336352func (h * HostInfo ) ClusterName () string {
337353 h .mu .RLock ()
338354 defer h .mu .RUnlock ()
339355 return h .clusterName
340356}
341357
358+ // Version returns version of the Cassandra instance.
342359func (h * HostInfo ) Version () cassVersion {
343360 h .mu .RLock ()
344361 defer h .mu .RUnlock ()
345362 return h .version
346363}
347364
365+ // State returns state of the node.
348366func (h * HostInfo ) State () nodeState {
349367 h .mu .RLock ()
350368 defer h .mu .RUnlock ()
@@ -358,12 +376,14 @@ func (h *HostInfo) setState(state nodeState) *HostInfo {
358376 return h
359377}
360378
379+ // Tokens returns slice of tokens.
361380func (h * HostInfo ) Tokens () []string {
362381 h .mu .RLock ()
363382 defer h .mu .RUnlock ()
364383 return h .tokens
365384}
366385
386+ // Port returns port which used for the connection.
367387func (h * HostInfo ) Port () int {
368388 h .mu .RLock ()
369389 defer h .mu .RUnlock ()
@@ -432,10 +452,13 @@ func (h *HostInfo) update(from *HostInfo) {
432452 }
433453}
434454
455+ // IsUp return true if the host is not nil and if the host state is node NodeUp.
435456func (h * HostInfo ) IsUp () bool {
436457 return h != nil && h .State () == NodeUp
437458}
438459
460+ // HostnameAndPort returns a network address of the form "host:port".
461+ // If host contains a colon - "[host]:port" will be returned.
439462func (h * HostInfo ) HostnameAndPort () string {
440463 h .mu .Lock ()
441464 defer h .mu .Unlock ()
@@ -446,6 +469,8 @@ func (h *HostInfo) HostnameAndPort() string {
446469 return net .JoinHostPort (h .hostname , strconv .Itoa (h .port ))
447470}
448471
472+ // ConnectAddressAndPort returns a network address of the form "host:port".
473+ // If connect address contains a colon - "[host]:port" will be returned.
449474func (h * HostInfo ) ConnectAddressAndPort () string {
450475 h .mu .Lock ()
451476 defer h .mu .Unlock ()
0 commit comments