Example #1
0
// ------------------------------------------
void PCPStream::readPushAtoms(AtomStream &atom, int numc, BroadcastState &bcs) {
    Host host;
    GnuID chanID;

    chanID.clear();

    for (int i = 0; i < numc; i++) {
        int c, d;
        ID4 id = atom.read(c, d);

        if (id == PCP_PUSH_IP)
            host.ip = atom.readInt();
        else if (id == PCP_PUSH_PORT)
            host.port = atom.readShort();
        else if (id == PCP_PUSH_CHANID)
            atom.readBytes(chanID.id, 16);
        else {
            LOG_DEBUG("PCP skip: %s,%d,%d", id.getString().str(), c, d);
            atom.skip(c, d);
        }
    }


    if (bcs.forMe) {
        char ipstr[64];
        host.toStr(ipstr);

        Servent *s = NULL;

        if (chanID.isSet()) {
            Channel *ch = chanMgr->findChannelByID(chanID);
            if (ch) if (ch->isBroadcasting() || !ch->isFull() && !servMgr->relaysFull() && ch->info.id.isSame(chanID))
                s = servMgr->allocServent();
        } else {
            s = servMgr->allocServent();
        }

        if (s) {
            LOG_DEBUG("GIVing to %s", ipstr);
            s->initGIV(host, chanID);
        }
    }

}