| 305 | |
| 306 | |
| 307 | class SniEndPointFactory(EndPointFactory): |
| 308 | |
| 309 | def __init__(self, proxy_address, port): |
| 310 | self._proxy_address = proxy_address |
| 311 | self._port = port |
| 312 | # Initial lookup index to prevent all SNI endpoints to be resolved |
| 313 | # into the same starting IP address (which might not be available currently). |
| 314 | # If SNI resolves to 3 IPs, first endpoint will connect to first |
| 315 | # IP address, and subsequent resolutions to next IPs in round-robin |
| 316 | # fusion. |
| 317 | self._init_index = -1 |
| 318 | |
| 319 | def create(self, row): |
| 320 | host_id = row.get("host_id") |
| 321 | if host_id is None: |
| 322 | raise ValueError("No host_id to create the SniEndPoint") |
| 323 | |
| 324 | self._init_index += 1 |
| 325 | return SniEndPoint(self._proxy_address, str(host_id), self._port, self._init_index) |
| 326 | |
| 327 | def create_from_sni(self, sni): |
| 328 | self._init_index += 1 |
| 329 | return SniEndPoint(self._proxy_address, sni, self._port, self._init_index) |
| 330 | |
| 331 | |
| 332 | @total_ordering |
no outgoing calls