void IntraMeshQueryClient::sendHeartbeat(int flags)
	{
		IntraMeshMsg::ptr outbound(new IntraMeshMsg(flags));

		if (! _sendActive) {
			_sendActive = true;

			_conn.async_send(
			  boost::asio::buffer(outbound->getDataStorage(), 
				outbound->getDataStorage().size()), 
			  boost::bind(&IntraMeshQueryClient::onAfterSendHeartbeat, this,
				boost::asio::placeholders::error,
				boost::asio::placeholders::bytes_transferred,
				outbound));

		} else {
			IQCSendItem item;
			item.message = outbound;
			item.callBack = 
				boost::bind(&IntraMeshQueryClient::onAfterSendHeartbeat, this, 
					boost::asio::placeholders::error,
					boost::asio::placeholders::bytes_transferred,
					outbound);

			_pendingSends.push(item);
		}
	}
Beispiel #2
0
void
Connection::doSetup()
{
    qDebug() << Q_FUNC_INFO << thread();
    /*
        New connections can be created from other thread contexts, such as
        when AudioEngine calls getIODevice.. - we need to ensure that connections
        and their associated sockets are running in the same thread as the servent.

        HINT: export QT_FATAL_WARNINGS=1 helps to catch these kind of errors.
     */
    if( QThread::currentThread() != m_servent->thread() )
    {
        // Connections should always be in the same thread as the servent.
        qDebug() << "Fixing thead affinity...";
        moveToThread( m_servent->thread() );
        qDebug() << Q_FUNC_INFO  << thread();
    }

    //stats timer calculates BW used by this connection
    m_statstimer = new QTimer;
    m_statstimer->moveToThread( this->thread() );
    m_statstimer->setInterval( 1000 );
    connect( m_statstimer, SIGNAL( timeout() ), SLOT( calcStats() ) );
    m_statstimer->start();
    m_statstimer_mark.start();

    m_sock->moveToThread( thread() );

    connect( m_sock.data(), SIGNAL( bytesWritten( qint64 ) ),
                              SLOT( bytesWritten( qint64 ) ), Qt::QueuedConnection );

    connect( m_sock.data(), SIGNAL( disconnected() ),
                              SLOT( socketDisconnected() ), Qt::QueuedConnection );

    connect( m_sock.data(), SIGNAL( error( QAbstractSocket::SocketError ) ),
                              SLOT( socketDisconnectedError( QAbstractSocket::SocketError ) ), Qt::QueuedConnection );

    connect( m_sock.data(), SIGNAL( readyRead() ),
                              SLOT( readyRead() ), Qt::QueuedConnection );

    // if connection not authed/setup fast enough, kill it:
    QTimer::singleShot( AUTH_TIMEOUT, this, SLOT( authCheckTimeout() ) );

    if( outbound() )
    {
        Q_ASSERT( !m_firstmsg.isNull() );
        sendMsg( m_firstmsg );
    }
    else
    {
        sendMsg( Msg::factory( PROTOVER, Msg::SETUP ) );
    }

    // call readyRead incase we missed the signal in between the servent disconnecting and us
    // connecting to the signal - won't do anything if there are no bytesAvailable anyway.
    readyRead();
}
	void IntraMeshQueryClient::sendAssetError(IntraMeshMsg::ptr inboundMsg)
	{
		if (_debugging) {
			SAFELOG(AppLog::instance().out() << "[IWINTRAMESH] Error checking for " 
				<< inboundMsg->getAssetUUID() 
				<< std::endl);
		}

		IntraMeshMsg::ptr outbound(new IntraMeshMsg(inboundMsg->getAssetUUID(), IntraMeshMsg::QR_ERROR));
		this->sendQueryResponse(outbound);
	}
	void IntraMeshQueryClient::sendAssetNotFound(IntraMeshMsg::ptr inboundMsg)
	{
		if (_debugging) {
			SAFELOG(AppLog::instance().out() << "[IWINTRAMESH] Asset not found for " 
				<< inboundMsg->getAssetUUID() 
				<< std::endl);
		}

		IntraMeshMsg::ptr outbound(new IntraMeshMsg(inboundMsg->getAssetUUID(), IntraMeshMsg::QR_NOTFOUND));
		this->sendQueryResponse(outbound);
	}
Beispiel #5
0
void
Connection::handleReadMsg()
{
    Q_D( Connection );

    if ( outbound() == false &&
        d->msg->is( Msg::SETUP ) &&
        d->msg->payload() == "ok" )
    {
        d->ready = true;
        tDebug( LOGVERBOSE ) << "Connection" << id() << "READY";
        setup();
        emit ready();
    }
    else if ( !d->ready &&
             outbound() &&
             d->msg->is( Msg::SETUP ) )
    {
        if ( d->msg->payload() == PROTOVER )
        {
            sendMsg( Msg::factory( "ok", Msg::SETUP ) );
            d->ready = true;
            tDebug( LOGVERBOSE ) << "Connection" << id() << "READY";
            setup();
            emit ready();
        }
        else
        {
            sendMsg( Msg::factory( "{\"method\":\"protovercheckfail\"}", Msg::JSON | Msg::SETUP ) );
            shutdown( true );
        }
    }
    else
    {
        d->msgprocessor_in.append( d->msg );
    }

    d->msg.clear();
}
	void IntraMeshQueryClient::sendAssetFound(IntraMeshMsg::ptr inboundMsg)
	{
		if (_debugging) {
			SAFELOG(AppLog::instance().out() << "[IWINTRAMESH] Asset found for " 
				<< inboundMsg->getAssetUUID() 
				<< std::endl);
		}

		//stats
		_meshService.addPositiveMeshRequestStat();

		IntraMeshMsg::ptr outbound(new IntraMeshMsg(inboundMsg->getAssetUUID(), IntraMeshMsg::QR_FOUND));
		this->sendQueryResponse(outbound);
	}
Beispiel #7
0
int main(int argc, char** argv) {
	if (argc != 4) {
		printf("USAGE: %s BITCOIND_ADDRESS BITCOIND_PORT LOCAL_ADDRESS\n", argv[0]);
		return -1;
	}

#ifdef WIN32
	WSADATA wsaData;
	if (WSAStartup(MAKEWORD(2,2), &wsaData))
		return -1;
#endif

	struct sockaddr_in6 addr;
	if (!lookup_address(argv[1], &addr)) {
		printf("Failed to lookup hostname\n");
		return -1;
	}
	std::string host(gethostname(&addr));

	P2PClient* inbound;
	P2PClient outbound(argv[1], std::stoul(argv[2]),
					[&](std::vector<unsigned char>& bytes, struct timeval) {
						struct timeval tv;
						gettimeofday(&tv, NULL);
						inbound->receive_block(bytes);

						std::vector<unsigned char> fullhash(32);
						CSHA256 hash; // Probably not BE-safe
						hash.Write(&bytes[sizeof(struct bitcoin_msg_header)], 80).Finalize(&fullhash[0]);
						hash.Reset().Write(&fullhash[0], fullhash.size()).Finalize(&fullhash[0]);
						for (unsigned int i = 0; i < fullhash.size(); i++)
							printf("%02x", fullhash[fullhash.size() - i - 1]);
						printf(" recv'd %s %lu\n", argv[1], uint64_t(tv.tv_sec)*1000 + uint64_t(tv.tv_usec)/1000);
					},
					[&](std::shared_ptr<std::vector<unsigned char> >& bytes) { inbound->receive_transaction(bytes); });
	inbound = new P2PClient(argv[3], 8334,
					[&](std::vector<unsigned char>& bytes, struct timeval) { outbound.receive_block(bytes); },
					[&](std::shared_ptr<std::vector<unsigned char> >& bytes) { });

	while (true) { sleep(1000); }
}
Beispiel #8
0
SIPXTAPI_API SIPX_RESULT sipxConfigVoicemailSubscribe(const SIPX_INST hInst,
                                                      const char* szSubscribeURL)
{
    OsSysLog::add(FAC_SIPXTAPI, PRI_INFO,
        "sipxConfigVoicemailSubscribe hInst=%p URL=%s",
        hInst, szSubscribeURL);

    SIPX_RESULT rc = SIPX_RESULT_INVALID_ARGS;
    SIPX_INSTANCE_DATA* pInst = (SIPX_INSTANCE_DATA*) hInst;

    assert(pInst);
    if (pInst)
    {
        assert(pInst->pRefreshManager);
        assert(pInst->pLineManager);
        assert(pInst->pSipUserAgent);
        if (pInst->pRefreshManager && pInst->pLineManager && pInst->pSipUserAgent)
        {
            if (szSubscribeURL != NULL)
            {
                UtlString userId;
                UtlString contactUri;
                UtlString outboundLine;
                Url subscribeUrl(szSubscribeURL);
                subscribeUrl.getUserId(userId);

                pInst->pLineManager->getDefaultOutboundLine(outboundLine);

                // If the PHONESET_MSG_WAITING_SUBSCRIBE setting does
                // not have a userid field specified, get the one
                // from the default outbound line and use that
                if( userId.isNull() )
                {
                    // get default outbound line from the line manager
                    Url outbound(outboundLine);
                    outbound.getUserId(userId);
                    subscribeUrl.setUserId(userId);
                }

                // make sure we associate a user with the line
                pInst->pSipUserAgent->getContactUri( &contactUri );
                Url contactForLine ( contactUri );
                contactForLine.setUserId( userId );

                UtlString contactforLineStr = contactForLine.toString();

                SipMessage* mwiSubscribeRequest = new SipMessage();

                int sipSubscribePeriodSeconds;

                // get the Subscribe Period from the RefreshManager
                sipSubscribePeriodSeconds = pInst->pRefreshManager->getSubscribeTimeout();

                mwiSubscribeRequest->setVoicemailData (
                    outboundLine.data(),           // fromField
                    outboundLine.data(),           // toField
                    subscribeUrl.toString().data(),// uri
                    contactforLineStr.data(),      // contactUrl
                    NULL,                          // callId, do not set here
                    1,                             // cseq
                    sipSubscribePeriodSeconds);    // expiresInSeconds

                // send the subscribe request to the refresh manager
                pInst->pRefreshManager->newSubscribeMsg( *mwiSubscribeRequest );
                rc = SIPX_RESULT_SUCCESS;
            }
        }
    }

    return rc;
}
Beispiel #9
0
int
process_ip(pcap_t *dev, const struct ip *ip, struct timeval tv) {
    char src[16], dst[16], *addr;
    int incoming;
    unsigned len;
    
    addr = inet_ntoa(ip->ip_src);
    strncpy(src, addr, 15);
    src[15] = '\0';
    
    addr = inet_ntoa(ip->ip_dst);
    strncpy(dst, addr, 15);
    dst[15] = '\0';
    
    if (is_local_address(ip->ip_src))
        incoming = 0;
    else if (is_local_address(ip->ip_dst))
        incoming = 1;
    else
        return 1;
    
    len = htons(ip->ip_len);
    
    switch (ip->ip_p) {
        struct tcphdr *tcp;
        uint16_t sport, dport, lport, rport;
        unsigned datalen;
    
    case IPPROTO_TCP:
        tcp = (struct tcphdr *) ((unsigned char *) ip + sizeof(struct ip));
        
#if defined(__FAVOR_BSD)
        sport = ntohs(tcp->th_sport);
        dport = ntohs(tcp->th_dport);
        datalen = len - sizeof(struct ip) - tcp->th_off * 4;    // 4 bits offset 
#else
        sport = ntohs(tcp->source);
        dport = ntohs(tcp->dest);
        datalen = len - sizeof(struct ip) - tcp->doff * 4;
#endif

        // Capture only "data" packets, ignore TCP control
        if (datalen == 0)
            break;

        if (incoming) {
            lport = dport;
            rport = sport;
            
            inbound(tv, ip->ip_dst, ip->ip_src, lport, rport);
            
        }
        else {
            lport = sport;
            rport = dport;
            
            outbound(tv, ip->ip_src, ip->ip_dst, lport, rport);
            
        }

        break;
        
    default:
        break;
        
    }
    
    return 0;
    
}