void agent_gather(struct agent *ag) { int err; if (!ag) return; net_if_apply(interface_handler, ag); re_printf("HOST gathering complete (interfaces = %u)\n", ag->interfacec); if (is_gathering_complete(ag)) { re_printf("local candidate gathering completed" " -- sending EOC\n"); ag->local_eoc = true; err = control_send_message(ag->cli, "a=end-of-candidates\r\n"); if (err) { re_fprintf(stderr, "failed to send EOC\n"); } } }
static void close_handler(int err, const struct sip_msg *msg, const struct sipevent_substate *substate, void *arg) { struct presence *pres = arg; uint32_t wait; pres->sub = mem_deref(pres->sub); (void)re_printf("presence: subscriber closed <%r>: ", &contact_addr(pres->contact)->auri); if (substate) { (void)re_printf("%s", sipevent_reason_name(substate->reason)); wait = wait_term(substate); } else if (msg) { (void)re_printf("%u %r", msg->scode, &msg->reason); wait = wait_fail(++pres->failc); } else { (void)re_printf("%m", err); wait = wait_fail(++pres->failc); } (void)re_printf("; will retry in %u secs (failc=%u)\n", wait, pres->failc); tmr_start(&pres->tmr, wait * 1000, tmr_handler, pres); contact_set_presence(pres->contact, PRESENCE_UNKNOWN); }
static void device_connect(struct device *device, struct device *peer_device) { struct peer *peer; ASSERT_TRUE(device != NULL); ASSERT_TRUE(peer_device != NULL); #if 0 re_printf("@@@ connect %s ----> %s\n", device->name, peer_device->name); #endif peer = device_find_peer(device, peer_device); if (peer) { re_printf("device %s already connected to %s\n", device->name, peer_device->name); } ASSERT_TRUE(peer == NULL); peer = (struct peer *)mem_zalloc(sizeof(*peer), peer_destructor); ASSERT_TRUE(peer != NULL); peer->device = peer_device; rand_str(peer->sid, sizeof(peer->sid)); list_append(&device->peerl, &peer->le, peer); }
static void dns_handler(int err, const struct dnshdr *hdr, struct list *ansl, struct list *authl, struct list *addl, void *arg) { struct rst *rst = arg; struct dnsrr *rr; struct sa srv; (void)err; (void)hdr; (void)authl; (void)addl; rr = dns_rrlist_find(ansl, rst->host, DNS_TYPE_A, DNS_CLASS_IN, true); if (!rr) { re_printf("rst: unable to resolve: %s\n", rst->host); tmr_start(&rst->tmr, RETRY_WAIT, reconnect, rst); return; } sa_set_in(&srv, rr->rdata.a.addr, rst->port); err = tcp_connect(&rst->tc, &srv, estab_handler, recv_handler, close_handler, rst); if (err) { re_printf("rst: tcp connect error: %m\n", err); tmr_start(&rst->tmr, RETRY_WAIT, reconnect, rst); return; } }
static void stun_dns_handler(int err, const struct sa *srv, void *arg) { struct candidate *cand = arg; if (err) { re_fprintf(stderr, "could not resolve STUN server (%m)\n", err); candidate_done(cand); return; } switch (cand->type) { case TYPE_STUN: re_printf("resolved STUN-server (%J)\n", srv); cand->stun_srv = *srv; gather_srflx2(cand, cand->base->attr.proto); break; case TYPE_TURN: re_printf("resolved TURN-server (%J)\n", srv); cand->turn_srv = *srv; gather_relay2(cand, cand->turn_proto); break; default: re_printf("unknown type\n"); break; } }
void allocator_print_statistics(const struct allocator *allocator) { struct le *le; double amin = 99999999, amax = 0, asum = 0, aavg; int ix_min = -1, ix_max = -1; /* show allocation summary */ if (!allocator || !allocator->num_sent) return; for (le = allocator->allocl.head; le; le = le->next) { struct allocation *alloc = le->data; if (alloc->atime < amin) { amin = alloc->atime; ix_min = alloc->ix; } if (alloc->atime > amax) { amax = alloc->atime; ix_max = alloc->ix; } asum += alloc->atime; } aavg = asum / allocator->num_sent; re_printf("\nAllocation time statistics:\n"); re_printf("min: %.1f ms (allocation #%d)\n", amin, ix_min); re_printf("avg: %.1f ms\n", aavg); re_printf("max: %.1f ms (allocation #%d)\n", amax, ix_max); re_printf("\n"); }
/* shared between STUN and TURN */ static void tcp_estab_handler(void *arg) { struct candidate *cand = arg; int err; re_printf("TCP established to STUN/TURN-server\n"); switch (cand->type) { case TYPE_STUN: err = stun_request(NULL, cand->ag->stun, IPPROTO_TCP, cand->tc, NULL, 0, STUN_METHOD_BINDING, NULL, 0, false, stun_resp_handler, cand, 0); if (err) { re_printf("tcp: stun_request failed (%m)\n", err); } break; case TYPE_TURN: err = turnc_alloc(&cand->turnc, NULL, IPPROTO_TCP, cand->tc, LAYER_TURN, &cand->turn_srv, cand->ag->cli->param.username, cand->ag->cli->param.password, TURN_DEFAULT_LIFETIME, turnc_handler, cand); if (err) { re_printf("tcp: turn client: %m\n", err); } break; } }
/* return TRUE if equal */ bool odict_compare(const struct odict *dict1, const struct odict *dict2) { struct le *le1, *le2; if (!dict1 || !dict2) return false; if (odict_count(dict1, true) != odict_count(dict2, true)) { re_printf("count mismatch\n"); return false; } for (le1 = dict1->lst.head, le2 = dict2->lst.head; le1 && le2; le1 = le1->next, le2 = le2->next) { struct odict_entry *e1 = le1->data; struct odict_entry *e2 = le2->data; if (0 != str_cmp(e1->key, e2->key)) { re_printf("key mismatch\n"); re_printf("(%s) %r\n", e1->key); re_printf("(%s) %r\n", e2->key); return false; } if (!odict_value_compare(e1, e2)) return false; } return true; /* equal */ }
static void tls_endpoint_estab_handler(const char *cipher, void *arg) { int err; (void)arg; re_fprintf(stderr, "\r[ %u .. %c ]", tlsperf.count, 0x20 + tlsperf.count % 0x60); if (tls_endpoint_established(tlsperf.ep_cli) && tls_endpoint_established(tlsperf.ep_srv)) { if (tlsperf.count >= tlsperf.num) { tlsperf.ts_estab = tmr_jiffies(); re_printf("\nDONE!\n"); re_printf("cipher: %s\n", cipher); print_report(); re_cancel(); } else { stop_test(); err = start_test(); if (err) abort_test(err); } } }
/** * Print a SIP Message to stdout * * @param msg SIP Message */ void sip_msg_dump(const struct sip_msg *msg) { struct le *le; uint32_t i; if (!msg) return; for (i=0; i<HDR_HASH_SIZE; i++) { le = list_head(hash_list(msg->hdrht, i)); while (le) { const struct sip_hdr *hdr = le->data; le = le->next; (void)re_printf("%02u '%r'='%r'\n", i, &hdr->name, &hdr->val); } } le = list_head(&msg->hdrl); while (le) { const struct sip_hdr *hdr = le->data; le = le->next; (void)re_printf("%02u '%r'='%r'\n", hdr->id, &hdr->name, &hdr->val); } }
static void estab_handler(void *arg) { struct rst *rst = arg; struct mbuf *mb; int err; re_printf("rst: connection established\n"); mb = mbuf_alloc(512); if (!mb) { err = ENOMEM; goto out; } err = mbuf_printf(mb, "GET %s HTTP/1.0\r\n" "Icy-MetaData: 1\r\n" "\r\n", rst->path); if (err) goto out; mb->pos = 0; err = tcp_send(rst->tc, mb); if (err) goto out; out: if (err) { re_printf("rst: error sending HTTP request: %m\n", err); } mem_deref(mb); }
/* * called when an SDP offer is received (got offer: true) or * when an offer is to be sent (got_offer: false) */ static int offer_handler(struct mbuf **mbp, const struct sip_msg *msg, void *arg) { const bool got_offer = mbuf_get_left(msg->mb); int err; (void)arg; if (got_offer) { err = sdp_decode(sdp, msg->mb, true); if (err) { re_fprintf(stderr, "unable to decode SDP offer: %s\n", strerror(err)); return err; } re_printf("SDP offer received\n"); update_media(); } else { re_printf("sending SDP offer\n"); } return sdp_encode(mbp, sdp, !got_offer); }
static int gather_srflx2(struct candidate *cand, int proto) { struct ice_lcand *base = cand->base; int err; switch (proto) { case IPPROTO_UDP: err = stun_keepalive_alloc(&cand->ska, proto, base->us, LAYER_STUN, &cand->stun_srv, NULL, stun_mapped_handler, cand); if (err) { re_printf("stun_request failed (%m)\n", err); } stun_keepalive_enable(cand->ska, 25); break; case IPPROTO_TCP: /* for TCP we must connect FROM the locally bound socket (either passive or S-O) */ re_printf("SRFLX tcp connecting.. %J -> %J\n", &base->attr.addr, &cand->stun_srv); err = tcp_conn_alloc(&cand->tc, &cand->stun_srv, tcp_estab_handler, tcp_recv_handler, tcp_close_handler, cand); if (err) { re_fprintf(stderr, "tcp_conn_alloc failed (%m)\n", err); return err; } err = tcp_conn_bind(cand->tc, &base->attr.addr); if (err) { re_fprintf(stderr, "tcp_conn_bind to %J failed" " (%m)\n", &base->attr.addr, err); return err; } err = tcp_conn_connect(cand->tc, &cand->stun_srv); if (err) { re_fprintf(stderr, "tcp_conn_connect to %J failed" " (%m)\n", err, &cand->stun_srv); return err; } break; default: return EPROTONOSUPPORT; } return 0; }
static int read_wav(kiss_fftr_cfg fft, const char *infile) { struct aufile *af_in = NULL; struct aufile_prm prm; size_t sampc_in_total = 0; size_t i; int err; err = aufile_open(&af_in, &prm, infile, AUFILE_READ); if (err) { re_fprintf(stderr, "%s: could not open input file (%m)\n", infile, err); goto out; } if (prm.fmt != AUFMT_S16LE) { err = EINVAL; goto out; } re_printf("%s: %u Hz, %d channels\n", infile, prm.srate, prm.channels); for (;;) { int16_t sampv[NUM_FFT]; size_t sz = sizeof(sampv); kiss_fft_cpx freqv[NUM_FREQ]; err = aufile_read(af_in, (void *)sampv, &sz); if (err || !sz) break; if (sz != sizeof(sampv)) { re_printf("skipping last %zu samples\n", sz); break; } sampc_in_total += (sz/2); /* do FFT transform */ kiss_fftr(fft, sampv, freqv); for (i=0; i<ARRAY_SIZE(freqv); i++) { kiss_fft_cpx cpx = freqv[i]; magv[i] += sqrt(cpx.r * cpx.r + cpx.i * cpx.i); } } re_printf("read %u samples\n", sampc_in_total); out: if (err) { re_fprintf(stderr, "file read error: %m\n", err); } mem_deref(af_in); return err; }
static void dump_stats(const struct videnc_state *ves) { re_printf("~~~~~ Daala Encoder stats ~~~~~\n"); re_printf("num frames: %zu\n", ves->stats.n_frame); re_printf("num headers: %zu\n", ves->stats.n_header); re_printf("key-frames packets: %zu\n", ves->stats.n_keyframe); re_printf("total packets: %zu\n", ves->stats.n_packet); }
int agent_process_remote_attr(struct agent *ag, const char *name, const char *value) { int err = 0; if (!ag || !name) return EINVAL; if (0 == str_casecmp(name, "ice-ufrag")) { ag->rufrag = true; err = trice_set_remote_ufrag(ag->icem, value); } else if (0 == str_casecmp(name, "ice-pwd")) { ag->rpwd = true; err = trice_set_remote_pwd(ag->icem, value); } else if (0 == str_casecmp(name, "candidate")) { unsigned i; err = agent_rcand_decode_add(ag->icem, value); for (i=0; i<ag->candc; i++) candidate_add_permissions(&ag->candv[i]); } else if (0 == str_casecmp(name, "end-of-candidates")) { re_printf("got end-of-candidates from remote\n"); ag->remote_eoc = true; } else { re_printf("attribute ignored: %s\n", name); } if (err) { re_printf("remote attr error (%m)\n", err); return err; } if (ag->rufrag && ag->rpwd && ag->cli->param.run_checklist && !list_isempty(trice_rcandl(ag->icem)) && !trice_checklist_isrunning(ag->icem)) { re_printf("starting ICE checklist with pacing interval" " %u milliseconds..\n", ag->cli->param.pacing_interval); err = trice_checklist_start(ag->icem, NULL, ag->cli->param.pacing_interval, true, ice_estab_handler, ice_failed_handler, ag); if (err) { re_fprintf(stderr, "could not start checklist (%m)\n", err); } } return 0; }
/* called when register responses are received */ static void register_handler(int err, const struct sip_msg *msg, void *arg) { (void)arg; if (err) re_printf("register error: %s\n", strerror(err)); else re_printf("register reply: %u %r\n", msg->scode, &msg->reason); }
/* called when SIP progress (like 180 Ringing) responses are received */ static void progress_handler(const struct sip_msg *msg, void *arg) { struct tcsipcall *call = arg; re_printf("session progress: %u %r\n", msg->scode, &msg->reason); if((msg->scode == 183) && mbuf_get_left(msg->mb)) { re_printf("early media"); tcmedia_answer(call->media, msg->mb); tcsipcall_activate(call); } }
/* called when the session fails to connect or is terminated from peer */ static void close_handler(int err, const struct sip_msg *msg, void *arg) { (void)arg; if (err) re_printf("session closed: %s\n", strerror(err)); else re_printf("session closed: %u %r\n", msg->scode, &msg->reason); terminate(); }
static void notify_handler(struct sip *sip, const struct sip_msg *msg, void *arg) { struct mwi *mwi = arg; if (mbuf_get_left(msg->mb)) { re_printf("----- MWI for %s -----\n", ua_aor(mwi->ua)); re_printf("%b\n", mbuf_buf(msg->mb), mbuf_get_left(msg->mb)); } (void)sip_treply(NULL, sip, msg, 200, "OK"); }
static bool interface_handler(const char *ifname, const struct sa *addr, void *arg) { struct agent *ag = arg; int err = 0; /* Skip loopback and link-local addresses */ if (ag->cli->param.skip_local) { if (sa_is_loopback(addr) || sa_is_linklocal(addr)) return false; } if (str_isset(ag->cli->param.ifname) && str_casecmp(ag->cli->param.ifname, ifname)) { return false; } switch (sa_af(addr)) { case AF_INET: if (!ag->cli->param.use_ipv4) return false; break; case AF_INET6: if (!ag->cli->param.use_ipv6) return false; break; } /* NOTE: on some machines an interface is listed twice. */ if (interface_find(ag, addr)) { re_printf("ignoring duplicated interface (%s %j)\n", ifname, addr); return false; } ag->interfacev[ag->interfacec++] = *addr; re_printf("interface: %s %j\n", ifname, addr); if (ag->cli->param.use_udp) err |= add_candidate(ag, addr, IPPROTO_UDP, 0, ifname); if (ag->cli->param.use_tcp) { err |= add_candidate(ag, addr, IPPROTO_TCP, ICE_TCP_SO, ifname); err |= add_candidate(ag, addr, IPPROTO_TCP, ag->client ? ICE_TCP_ACTIVE : ICE_TCP_PASSIVE, ifname); } return err != 0; }
void debug() { struct le *le; re_printf("DEVICES (%u):\n", list_count(&devicel)); for (le = devicel.head; le; le = le->next) { struct device *dev = (struct device *)le->data; re_printf("...device %s (peers = %u)\n", dev->name, list_count(&dev->peerl)); } }
void gst_dump_props(GstElement *g) { uint64_t u64; gchar *strval; double volume; int n; re_printf("Gst properties:\n"); g_object_get(g, "delay", &u64, NULL); re_printf(" delay: %lu ns\n", u64); g_object_get(g, "uri", &strval, NULL); re_printf(" uri: %s\n", strval); g_free(strval); g_object_get(g, "suburi", &strval, NULL); re_printf(" suburi: %s\n", strval); g_free(strval); g_object_get(g, "queue-size", &u64, NULL); re_printf(" queue-size: %lu ns\n", u64); g_object_get(g, "queue-threshold", &u64, NULL); re_printf(" queue-threshold: %lu ns\n", u64); g_object_get(g, "nstreams", &n, NULL); re_printf(" nstreams: %d\n", n); g_object_get(g, "volume", &volume, NULL); re_printf(" Volume: %f\n", volume); }
/* print SDP status */ static void update_media(void) { const struct sdp_format *fmt; re_printf("SDP peer address: %J\n", sdp_media_raddr(sdp_media)); fmt = sdp_media_rformat(sdp_media, NULL); if (!fmt) { re_printf("no common media format found\n"); return; } re_printf("SDP media format: %s/%u/%u (payload type: %u)\n", fmt->name, fmt->srate, fmt->ch, fmt->pt); }
static bool helper_recv_handler(struct sa *src, struct mbuf *mb, void *arg) { struct icem_comp *comp = arg; struct icem *icem = comp->icem; struct stun_msg *msg = NULL; struct stun_unknown_attr ua; const size_t start = mb->pos; #if 0 re_printf("{%d} UDP recv_helper: %u bytes from %J\n", comp->id, mbuf_get_left(mb), src); #endif if (stun_msg_decode(&msg, mb, &ua)) return false; if (STUN_METHOD_BINDING == stun_msg_method(msg)) { switch (stun_msg_class(msg)) { case STUN_CLASS_REQUEST: (void)icem_stund_recv(comp, src, msg, start); break; default: (void)stun_ctrans_recv(icem->ice->stun, msg, &ua); break; } } mem_deref(msg); return true; /* handled */ }
static int oss_reset(int fd, uint32_t srate, uint8_t ch, int frame_size, int nonblock) { int format = AFMT_S16_LE; int speed = srate; int channels = ch; int blocksize = 0; int err; err = set_fragment(fd, frame_size); if (err) return err; if (0 != ioctl(fd, FIONBIO, &nonblock)) return errno; if (0 != ioctl(fd, SNDCTL_DSP_SETFMT, &format)) return errno; if (0 != ioctl(fd, SNDCTL_DSP_CHANNELS, &channels)) return errno; if (2 == channels) { int stereo = 1; if (0 != ioctl(fd, SNDCTL_DSP_STEREO, &stereo)) return errno; } if (0 != ioctl(fd, SNDCTL_DSP_SPEED, &speed)) return errno; (void)ioctl(fd, SNDCTL_DSP_GETBLKSIZE, &blocksize); re_printf("oss init: %u bit %d Hz %d ch, blocksize=%d\n", format, speed, channels, blocksize); return 0; }
/* called upon reception of SIGINT, SIGALRM or SIGTERM */ static void signal_handler(int sig) { re_printf("terminating on signal %d...\n", sig); /* stop libre main loop */ re_cancel(); }
void p2p_connect_handler(int err, const char* reason, struct p2pconnection* p2pcon) { re_printf("connect ok"); int fdlisten = tcp_conn_fd(p2pcon->p2p->ltcp); UDPSOCKET udpsock = (UDPSOCKET)fdlisten; UDT::connect(p2pcon->udtsock, &udpsock, &(p2pcon->p2p->sactl->u.sa), p2pcon->p2p->sactl->len); }
/* PLC is only valid for Decoding (RX) */ static int dec(struct aufilt_st *st, struct mbuf *mb) { int nsamp = (int)mbuf_get_left(mb) / 2; if (nsamp) { nsamp = plc_rx(&st->plc, (int16_t *)mbuf_buf(mb), nsamp); if (nsamp >= 0) mb->end = mb->pos + (2*nsamp); } else { nsamp = (int)st->psize / 2; re_printf("plc: concealing %u bytes\n", st->psize); if (mbuf_get_space(mb) < st->psize) { int err = mbuf_resize(mb, st->psize); if (err) return err; } nsamp = plc_fillin(&st->plc, (int16_t *)mbuf_buf(mb), nsamp); mb->end = mb->pos + 2 * nsamp; } return 0; }
static int device_new_session(struct device *device, struct device *other) { struct peer *peer; const char *sid; CBoxResult rc; peer = device_find_peer(device, other); if (!peer) return ENOENT; sid = peer->sid; if (!peer->session) { rc = cbox_session_init_from_prekey(device->box, sid, cbox_vec_data(other->prekey), cbox_vec_len(other->prekey), &peer->session); assert(rc == CBOX_SUCCESS); assert(peer->session != NULL); #if 0 re_printf("[ %s ] new session with device %s (sid=%s)\n", device->name, other->name, sid); #endif } return 0; }