RegisterToProxy is just like RegisterForever but registers the given URL to kontrol over a kite-proxy. A Kiteproxy is a reverseproxy that can be used for SSL termination or handling hundreds of kites behind a single. This is a blocking function.
(registerURL *url.URL, query *protocol.KontrolQuery)
| 410 | // for SSL termination or handling hundreds of kites behind a single. This is a |
| 411 | // blocking function. |
| 412 | func (k *Kite) RegisterToProxy(registerURL *url.URL, query *protocol.KontrolQuery) { |
| 413 | go k.RegisterForever(nil) |
| 414 | |
| 415 | for { |
| 416 | var proxyKite *Client |
| 417 | |
| 418 | // The proxy kite to connect can be overridden with the |
| 419 | // environmental variable "KITE_PROXY_URL". If it is not set |
| 420 | // we will ask Kontrol for available Proxy kites. |
| 421 | // As an authentication informain kiteKey method will be used, |
| 422 | // so be careful when using this feature. |
| 423 | kiteProxyURL := os.Getenv("KITE_PROXY_URL") |
| 424 | if kiteProxyURL != "" { |
| 425 | proxyKite = k.NewClient(kiteProxyURL) |
| 426 | proxyKite.Auth = &Auth{ |
| 427 | Type: "kiteKey", |
| 428 | Key: k.KiteKey(), |
| 429 | } |
| 430 | } else { |
| 431 | kites, err := k.GetKites(query) |
| 432 | if err != nil { |
| 433 | k.Log.Error("Cannot get Proxy kites from Kontrol: %s", err.Error()) |
| 434 | time.Sleep(proxyRetryDuration) |
| 435 | continue |
| 436 | } |
| 437 | |
| 438 | // If more than one one Proxy Kite is available pick one randomly. |
| 439 | // It does not matter which one we connect. |
| 440 | proxyKite = kites[rand.Int()%len(kites)] |
| 441 | } |
| 442 | |
| 443 | // Notify us on disconnect |
| 444 | disconnect := make(chan bool, 1) |
| 445 | proxyKite.OnDisconnect(func() { |
| 446 | select { |
| 447 | case disconnect <- true: |
| 448 | default: |
| 449 | } |
| 450 | }) |
| 451 | |
| 452 | proxyURL, err := k.registerToProxyKite(proxyKite, registerURL) |
| 453 | if err != nil { |
| 454 | time.Sleep(proxyRetryDuration) |
| 455 | continue |
| 456 | } |
| 457 | |
| 458 | k.kontrol.registerChan <- proxyURL |
| 459 | |
| 460 | // Block until disconnect from Proxy Kite. |
| 461 | <-disconnect |
| 462 | } |
| 463 | } |
| 464 | |
| 465 | // registerToProxyKite dials the proxy kite and calls register method then |
| 466 | // returns the reverse-proxy URL. |
no test coverage detected