1616 Location () string
1717 LastUpdated () time.Time
1818 LoadFactor () float32
19+ OverrideHost () string
1920
2021 // Deprecated: LocalDC check "local" by compare endpoint location with discovery "selflocation" field.
2122 // It work good only if connection url always point to local dc.
@@ -33,11 +34,14 @@ type (
3334)
3435
3536type endpoint struct { //nolint:maligned
36- mu sync.RWMutex
37- id uint32
38- address string
39- location string
40- services []string
37+ mu sync.RWMutex
38+ id uint32
39+ address string
40+ location string
41+ services []string
42+ ipv4 []string
43+ ipv6 []string
44+ sslNameOverride string
4145
4246 loadFactor float32
4347 lastUpdated time.Time
@@ -50,13 +54,16 @@ func (e *endpoint) Copy() Endpoint {
5054 defer e .mu .RUnlock ()
5155
5256 return & endpoint {
53- id : e .id ,
54- address : e .address ,
55- location : e .location ,
56- services : append (make ([]string , 0 , len (e .services )), e .services ... ),
57- loadFactor : e .loadFactor ,
58- local : e .local ,
59- lastUpdated : e .lastUpdated ,
57+ id : e .id ,
58+ address : e .address ,
59+ location : e .location ,
60+ services : append (make ([]string , 0 , len (e .services )), e .services ... ),
61+ ipv4 : append (make ([]string , 0 , len (e .ipv4 )), e .ipv4 ... ),
62+ ipv6 : append (make ([]string , 0 , len (e .ipv6 )), e .ipv6 ... ),
63+ sslNameOverride : e .sslNameOverride ,
64+ loadFactor : e .loadFactor ,
65+ local : e .local ,
66+ lastUpdated : e .lastUpdated ,
6067 }
6168}
6269
@@ -81,13 +88,47 @@ func (e *endpoint) NodeID() uint32 {
8188 return e .id
8289}
8390
91+ func getResolvedAddr (e * endpoint , useV6 bool ) string {
92+ var ip string
93+ if useV6 {
94+ ip = "[" + e .ipv6 [0 ] + "]"
95+ } else {
96+ ip = e .ipv4 [0 ]
97+ }
98+
99+ end := len (e .address )
100+
101+ for i := end - 1 ; i >= 0 ; i -- {
102+ if e .address [i ] == ':' {
103+ return ip + e .address [i :]
104+ }
105+ }
106+
107+ return e .address
108+ }
109+
84110func (e * endpoint ) Address () (address string ) {
85111 e .mu .RLock ()
86112 defer e .mu .RUnlock ()
87113
114+ if len (e .ipv4 ) != 0 {
115+ return getResolvedAddr (e , false )
116+ }
117+
118+ if len (e .ipv6 ) != 0 {
119+ return getResolvedAddr (e , true )
120+ }
121+
88122 return e .address
89123}
90124
125+ func (e * endpoint ) OverrideHost () string {
126+ e .mu .RLock ()
127+ defer e .mu .RUnlock ()
128+
129+ return e .sslNameOverride
130+ }
131+
91132func (e * endpoint ) Location () string {
92133 e .mu .RLock ()
93134 defer e .mu .RUnlock ()
@@ -168,6 +209,24 @@ func WithLastUpdated(ts time.Time) Option {
168209 }
169210}
170211
212+ func WithIPV4 (ipv4 []string ) Option {
213+ return func (e * endpoint ) {
214+ e .ipv4 = append (e .ipv4 , ipv4 ... )
215+ }
216+ }
217+
218+ func WithIPV6 (ipv6 []string ) Option {
219+ return func (e * endpoint ) {
220+ e .ipv6 = append (e .ipv6 , ipv6 ... )
221+ }
222+ }
223+
224+ func WithSslTargetNameOverride (nameOverride string ) Option {
225+ return func (e * endpoint ) {
226+ e .sslNameOverride = nameOverride
227+ }
228+ }
229+
171230func New (address string , opts ... Option ) * endpoint {
172231 e := & endpoint {
173232 address : address ,
0 commit comments