MCPcopy Index your code
hub / github.com/koding/kite / RegisterToProxy

Method RegisterToProxy

kontrolclient.go:412–463  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

410// for SSL termination or handling hundreds of kites behind a single. This is a
411// blocking function.
412func (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.

Callers 1

RegisterToTunnelMethod · 0.95

Calls 7

RegisterForeverMethod · 0.95
NewClientMethod · 0.95
KiteKeyMethod · 0.95
GetKitesMethod · 0.95
OnDisconnectMethod · 0.95
registerToProxyKiteMethod · 0.95
ErrorMethod · 0.65

Tested by

no test coverage detected