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

Method SetupKontrolClient

kontrolclient.go:53–102  ·  view source on GitHub ↗

SetupKontrolClient setups and prepares a the kontrol instance. It connects to kontrol and reconnects again if there is any disconnections. This method is called internally whenever a kontrol client specific action is taking. However if you wish to connect earlier you may call this method.

()

Source from the content-addressed store, hash-verified

51// is called internally whenever a kontrol client specific action is taking.
52// However if you wish to connect earlier you may call this method.
53func (k *Kite) SetupKontrolClient() error {
54 if k.kontrol.Client != nil {
55 return nil // already prepared
56 }
57
58 if k.Config.KontrolURL == "" {
59 return errors.New("no kontrol URL given in config")
60 }
61
62 client := k.NewClient(k.Config.KontrolURL)
63 client.Kite = protocol.Kite{Name: "kontrol"} // for logging purposes
64 client.Auth = &Auth{
65 Type: "kiteKey",
66 Key: k.KiteKey(),
67 }
68
69 k.kontrol.Lock()
70 k.kontrol.Client = client
71 k.kontrol.Unlock()
72
73 k.kontrol.OnConnect(func() {
74 k.Log.Info("Connected to Kontrol")
75 k.Log.Debug("Connected to Kontrol with session %q", client.session.ID())
76
77 // try to re-register on connect
78 k.kontrol.Lock()
79 if k.kontrol.lastRegisteredURL != nil {
80 select {
81 case k.kontrol.registerChan <- k.kontrol.lastRegisteredURL:
82 default:
83 }
84 }
85 k.kontrol.Unlock()
86
87 // signal all other methods that are listening on this channel, that we
88 // are connected to kontrol.
89 k.kontrol.onceConnected.Do(func() { close(k.kontrol.readyConnected) })
90 })
91
92 k.kontrol.OnDisconnect(func() {
93 k.Log.Warning("Disconnected from Kontrol.")
94 })
95
96 // non blocking, is going to reconnect if the connection goes down.
97 if _, err := k.kontrol.DialForever(); err != nil {
98 return err
99 }
100
101 return nil
102}
103
104// GetKites returns the list of Kites matching the query. The returned list
105// contains Ready to connect Client instances. The caller must connect

Callers 8

GetKitesMethod · 0.95
GetTokenMethod · 0.95
SendWebRTCRequestMethod · 0.95
GetTokenForceMethod · 0.95
GetKeyMethod · 0.95
RegisterMethod · 0.95
TestMultipleFunction · 0.80

Calls 10

NewClientMethod · 0.95
KiteKeyMethod · 0.95
InfoMethod · 0.80
DebugMethod · 0.80
DoMethod · 0.80
WarningMethod · 0.80
DialForeverMethod · 0.80
OnConnectMethod · 0.45
IDMethod · 0.45
OnDisconnectMethod · 0.45

Tested by 1

TestMultipleFunction · 0.64