MCPcopy Create free account
hub / github.com/bloomberg/comdb2 / hello_msg_common

Function hello_msg_common

net/net_evbuffer.c:1260–1329  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1258}
1259
1260static int hello_msg_common(struct event_info *e)
1261{
1262 int rc = -1;
1263 uint32_t nn;
1264 uint8_t *buf = e->rd_buf;
1265 memcpy(&nn, buf, sizeof(nn));
1266 buf += sizeof(nn);
1267 const uint32_t n = htonl(nn);
1268 if (n > REPMAX) {
1269 hprintf("RECV'd BAD COUNT OF HOSTS:%u (max:%d)\n", n, REPMAX);
1270 return -1;
1271 }
1272 char **hosts = malloc(sizeof(char *) * n);
1273 for (uint32_t i = 0; i < n; ++i) {
1274 hosts[i] = malloc(HOSTNAME_LEN + 1);
1275 memcpy(hosts[i], buf, HOSTNAME_LEN);
1276 buf += HOSTNAME_LEN;
1277 hosts[i][HOSTNAME_LEN] = 0;
1278 }
1279 uint32_t *ports = malloc(sizeof(uint32_t) * n);
1280 for (uint32_t i = 0; i < n; ++i) {
1281 memcpy(&ports[i], buf, sizeof(uint32_t));
1282 buf += sizeof(ports[i]);
1283 ports[i] = htonl(ports[i]);
1284 }
1285 buf += (n * sizeof(uint32_t)); /* We have no use for node numbers */
1286 for (uint32_t i = 0; i < n; ++i) {
1287 int need_free = 0;
1288 char *host = hosts[i];
1289 if (*host == '.') {
1290 ++host;
1291 uint32_t s = atoi(host);
1292 if (s > HOST_NAME_MAX) {
1293 hprintf("RECV'd BAD HOSTNAME len:%u (max:%d)\n", s, HOST_NAME_MAX);
1294 goto out;
1295 }
1296 need_free = 1;
1297 host = malloc(s + 1);
1298 memcpy(host, buf, s);
1299 buf += s;
1300 host[s] = 0;
1301 }
1302 if (strcmp(host, gbl_myhostname) == 0) {
1303 if (need_free) free(host);
1304 continue;
1305 }
1306 struct host_info *hi = host_info_find(host);
1307 if (hi && event_info_find(e->net_info, hi)) {
1308 if (need_free) free(host);
1309 continue;
1310 }
1311 char *ihost = intern(host);
1312 if (need_free) free(host);
1313 netinfo_type *netinfo_ptr = e->net_info->netinfo_ptr;
1314 if (netinfo_ptr->allow_rtn && !netinfo_ptr->allow_rtn(netinfo_ptr, ihost)) { /* net_allow_node */
1315 logmsg(LOGMSG_ERROR, "connection to host:%s not allowed\n", ihost);
1316 continue;
1317 }

Callers 2

process_hello_msgFunction · 0.85
process_hello_replyFunction · 0.85

Calls 8

mallocFunction · 0.85
freeFunction · 0.85
host_info_findFunction · 0.85
event_info_findFunction · 0.85
internFunction · 0.85
run_on_baseFunction · 0.85
set_hello_messageFunction · 0.85
logmsgFunction · 0.50

Tested by

no test coverage detected