MCPcopy Create free account
hub / github.com/CalcProgrammer1/OpenRGB / connect

Method connect

dependencies/hueplusplus-1.0.0/src/EntertainmentMode.cpp:142–265  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

140}
141
142bool EntertainmentMode::connect()
143{
144 /*-------------------------------------------------*\
145 | Signal the bridge to start streaming |
146 | If successful, connect to the UDP port |
147 \*-------------------------------------------------*/
148 if (bridge->startStreaming(std::to_string(group->getId())))
149 {
150 /*-------------------------------------------------*\
151 | Connect to the Hue bridge UDP server |
152 \*-------------------------------------------------*/
153 int ret = mbedtls_net_connect(
154 &tls_context->server_fd, bridge->getBridgeIP().c_str(), "2100", MBEDTLS_NET_PROTO_UDP);
155
156 /*-------------------------------------------------*\
157 | If connecting failed, close and return false |
158 \*-------------------------------------------------*/
159 if (ret != 0)
160 {
161 mbedtls_ssl_close_notify(&tls_context->ssl);
162 bridge->stopStreaming(std::to_string(group->getId()));
163 return false;
164 }
165
166 /*-------------------------------------------------*\
167 | Configure defaults |
168 \*-------------------------------------------------*/
169 ret = mbedtls_ssl_config_defaults(
170 &tls_context->conf, MBEDTLS_SSL_IS_CLIENT, MBEDTLS_SSL_TRANSPORT_DATAGRAM, MBEDTLS_SSL_PRESET_DEFAULT);
171
172 /*-------------------------------------------------*\
173 | If configuring failed, close and return false |
174 \*-------------------------------------------------*/
175 if (ret != 0)
176 {
177 mbedtls_ssl_close_notify(&tls_context->ssl);
178 bridge->stopStreaming(std::to_string(group->getId()));
179 return false;
180 }
181
182 mbedtls_ssl_conf_authmode(&tls_context->conf, MBEDTLS_SSL_VERIFY_OPTIONAL);
183 mbedtls_ssl_conf_ca_chain(&tls_context->conf, &tls_context->cacert, NULL);
184 mbedtls_ssl_conf_rng(&tls_context->conf, mbedtls_ctr_drbg_random, &tls_context->ctr_drbg);
185
186 /*-------------------------------------------------*\
187 | Convert client key to binary array |
188 \*-------------------------------------------------*/
189 std::vector<char> psk_binary = hexToBytes(bridge->getClientKey());
190
191 /*-------------------------------------------------*\
192 | Configure SSL pre-shared key and identity |
193 | PSK - binary array from client key |
194 | Identity - username (ASCII) |
195 \*-------------------------------------------------*/
196 ret = mbedtls_ssl_conf_psk(&tls_context->conf, (const unsigned char*)&psk_binary[0], psk_binary.size(),
197 (const unsigned char*)bridge->getUsername().c_str(), bridge->getUsername().length());
198
199 /*-------------------------------------------------*\

Callers 1

ConnectMethod · 0.80

Calls 15

to_stringFunction · 0.85
mbedtls_net_connectFunction · 0.85
mbedtls_ssl_close_notifyFunction · 0.85
mbedtls_ssl_conf_rngFunction · 0.85
hexToBytesFunction · 0.85
mbedtls_ssl_conf_pskFunction · 0.85
mbedtls_ssl_setupFunction · 0.85
mbedtls_ssl_set_hostnameFunction · 0.85
mbedtls_ssl_set_bioFunction · 0.85

Tested by

no test coverage detected