Ejemplo n.º 1
0
bool SCENEGRAPH::addNode( SGNODE* aNode, bool isChild )
{
    if( NULL == aNode )
    {
        #ifdef DEBUG
        std::ostringstream ostr;
        ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
        ostr << " * [BUG] NULL pointer passed for aNode";
        wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
        #endif

        return false;
    }

    ADD_NODE( S3D::SGTYPE_TRANSFORM, SCENEGRAPH, aNode, m_Transforms, m_RTransforms, isChild );
    ADD_NODE( S3D::SGTYPE_SHAPE, SGSHAPE, aNode, m_Shape, m_RShape, isChild );

    #ifdef DEBUG
    do {
        std::ostringstream ostr;
        ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
        ostr << " * [BUG] object '" << aNode->GetName();
        ostr << "' is not a valid type for this object (" << aNode->GetNodeType() << ")";
        wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
    } while( 0 );
    #endif

    return false;
}
Ejemplo n.º 2
0
// 添加客户端
CStatInfo::_ClientInfo *CStatInfo::AddClient( const char *ip, unsigned short tcpport, unsigned short udpport )
{
	_ClientInfo *p = NULL ;
	CMapClient::iterator it = _mpClient.find( ip ) ;
	if ( it == _mpClient.end() ) {
		p = new _ClientInfo ;
		p->_ip     = ip ;
		p->_errcnt = 0 ;
		p->_tcp    = tcpport ;
		p->_udp    = udpport ;
		p->_login  = time(NULL) ;
		p->_time   = time(NULL) ;
		p->_tail   = p->_head = NULL ;
		p->_size   = 0 ;
		p->_send   = 0 ;
		p->_recv   = 0 ;

		ADD_NODE( _head, _tail, p ) ;

		++ _size ;

		_mpClient.insert( CMapClient::value_type(ip, p ) ) ;

	} else {
		p = it->second ;
		if ( tcpport > 0 ) {
			p->_tcp = tcpport ;
		}
		if ( udpport > 0 ) {
			p->_udp = udpport ;
		}
		p->_time = time(NULL) ;
	}
	return p ;
}
Ejemplo n.º 3
0
// 是否出错
void CStatInfo::AddVechile( const char *ip, const char *carnum, unsigned char color, bool error )
{
	if ( carnum == NULL )
		return ;

	share::Guard g( _mutex ) ;

	_ClientInfo *p = AddClient( ip, 0, 0 ) ;
	if ( p == NULL )
		return ;

	_CarInfo *info = NULL ;

	CMapCar::iterator it = p->_mpcar.find( carnum ) ;
	if ( it == p->_mpcar.end() ) {
		info = new _CarInfo ;
		info->_time     = time(NULL) ;
		info->_carnum   = carnum ;
		info->_carcolor = color ;
		info->_errcnt   = 0 ;
		if ( error ) {
			++ info->_errcnt ;
			++ p->_errcnt ;
		}
		ADD_NODE( p->_head, p->_tail, info ) ;
		p->_mpcar.insert( CMapCar::value_type( carnum, info ) ) ;
		++ p->_size ;

	} else {
		info = it->second ;
		info->_time = time(NULL) ;
		info->_errcnt = info->_errcnt + ( error ) ? 1 : 0  ;
	}
}
Ejemplo n.º 4
0
void
IfShape::addNodesForLevel(SoGroup *group, int level)
{

#define ADD_NODE(n)	if (n != NULL) group->addChild(n)

#define ADD_LIST(l)	if (l != NULL) {				      \
			    for (i = 0; i < (*l).getLength(); i++)	      \
				group->addChild((*l)[i]);		      \
			}

    int i;
    ASSERT(level > 0 && level <= 5);

    switch (level) {

      case 1:
	ADD_NODE(camera);
	break;

      case 2:
	ADD_LIST(lights);
	ADD_LIST(clipPlanes);
	ADD_NODE(environment);
	ADD_NODE(lightModel);
	break;

      case 3:
	ADD_NODE(texture);
	break;

      case 4:
	ADD_NODE(drawStyle);
	ADD_NODE(shapeHints);
	ADD_NODE(material);
	ADD_LIST(other);
	break;

      case 5:
	// For level 5, we add each set of nodes under its own
	// separator
	{
	    SoSeparator *sep = new SoSeparator;
	    group->addChild(sep);
	    group = sep;
	}
	ADD_NODE(complexity);
	ADD_NODE(coords);
	ADD_NODE(font);
	ADD_NODE(materialBinding);
	ADD_NODE(normals);
	ADD_NODE(normalBinding);
	ADD_NODE(profileCoords);
	ADD_LIST(profiles);
	ADD_NODE(texCoords);
	ADD_NODE(texCoordBinding);
	// Handle matrices specially
	if (transform != SbMatrix::identity()) {
	    SoMatrixTransform *xf = new SoMatrixTransform;
	    group->addChild(xf);
	    xf->matrix = transform;
	}
	ADD_LIST(textureTransforms);
	ADD_NODE(shape);
	break;

      default:
	fprintf(stderr, "Error in IfShape::addNodesForLevel(level %d)\n", level);
    }

#undef ADD_NODE
#undef ADD_LIST
}
Ejemplo n.º 5
0
void testSearch(struct DHTMessage** outMessagePtr,
                struct RouterModule* routerModule,
                struct DHTModuleRegistry* registry,
                struct Allocator* allocator)
{
    *outMessagePtr = NULL;

    #define REQUEST_HASH "\xfc\x01\x01\x01\x01\x01\x01\x01\x21\x01\x01\x01\x01\x01\x01\x01"

    struct DHTMessage* callbackMessage = NULL;

    RouterModule_beginSearch((uint8_t*) REQUEST_HASH,
                             testSearch_callback,
                             &callbackMessage,
                             routerModule);

    struct DHTMessage* outMessage = *outMessagePtr;
    assert(outMessage != NULL);

    // Need to be able to work around the fact that the string contains nulls.
    #define EXPECTED_OUTPUT(tid) \
        "d"                                     \
          "1:q" "2:fn"                          \
          "3:tar" "16:" REQUEST_HASH            \
          "4:txid" "2:" tid                     \
        "e"

    for (uint32_t i = 0; i < (uint32_t) outMessage->length; i++) {
      //printf("%.2X", (unsigned int) outMessage->bytes[i] & 0xFF);
    }
    //printf("\n%s\n", outMessage->bytes);
    //printf("\n%s\n", outMessage->peerAddress);

    assert(outMessage->length == strlen(EXPECTED_OUTPUT("xx")));
    assert(memcmp(outMessage->bytes, EXPECTED_OUTPUT("8\x00"), outMessage->length) == 0);
    //assert(strcmp(outMessage->address->networkAddress, " 00014  ") == 0);
    // In a normal DHT, 00014 is the closest node, however, 00011 has sent us a message in
    // testQuery() and thus his reach is 1 and he beats all other nodes which are 0-reach.
    // Search queries are allowed to select nodes which are further from the target than us.
    assert(strcmp((char*) &outMessage->address->networkAddress_be, " 00011  ") == 0);

    #undef EXPECTED_OUTPUT

    #define CRAFTED_REPLY(tid) \
        "d"                                                    \
          "1:n" "200:"                                         \
            "97bkjs8qpd5hc1mubj3qbfyqzmzxp3rg" " 00017  "      \
            "by1szn122nqk1vncjtm612444rlh6ztr" " 00018  "      \
            "u42wbyr0wznhkbqr1r7u627dwsvb8853" " 00019  "      \
            "97bkjs8qpd5hc1mubj3qbfyqzmzxp3rg" " 00020  "      \
            "2lr8w01hhrxqng8mm8nf3nlwh5nyxzyl" " 00021  "      \
          "4:txid" "2:" tid                                    \
        "e"

    struct Address address = {
        .key = "ponmlkjihgzyxwvutsrq           \0"
    };
    memcpy(&address.networkAddress_be, " 00011  ", 8);

    struct DHTMessage message =
    {
        .length = strlen(CRAFTED_REPLY("xx")),
        .allocator = allocator,
        .address = &address
    };
    memcpy(message.bytes, CRAFTED_REPLY("8\x00"), message.length);
   // memcpy(message.peerAddress, peerAddress, 18);

    *outMessagePtr = NULL;

    DHTModules_handleIncoming(&message, registry);

    // Make sure the callback was called.
    assert(callbackMessage != NULL);

    // Make sure the node was promoted for it's fine service :P
    struct Address addr;
    memset(&addr, 0, sizeof(struct Address));
    memcpy(&addr.key, "ponmlkjihgzyxwvutsrq           \0", 32);
    struct Node* node1 =
        NodeStore_getNode(routerModule->nodeStore, &addr);
    //printf("node reach = %d", node1->reach);
    assert(node1->reach == 1601894175);

 /*   outMessage = *outMessagePtr;
    assert(outMessage != NULL);

    assert(strcmp("000022", outMessage->peerAddress) == 0);*/
}

int main()
{
    char buffer[1<<20];
    struct Allocator* allocator = BufferAllocator_new(buffer, 1<<20);
    struct DHTModuleRegistry* registry = DHTModules_new(allocator);

    ReplyModule_register(registry, allocator);
    struct RouterModule* routerModule =
        RouterModule_register(registry, allocator, (uint8_t*) MY_ADDRESS, event_base_new(), NULL);

    SerializationModule_register(registry, allocator);

    struct DHTMessage* outMessage;
    // dummy "network module" which just catches outgoing messages and makes them available.
    TestFramework_registerOutputCatcher(&outMessage, registry, allocator);

    struct Address addr;

    // damn this \0, was a mistake but to fix it would break all of the hashes :(
    #define ADD_NODE(address, netAddr) \
        memset(&addr, 0, sizeof(struct Address));                             \
        memcpy(&addr.networkAddress_be, netAddr "  ", 8);                     \
        memcpy(&addr.key, (uint8_t*) address "           \0", 32);            \
        RouterModule_addNode(&addr, routerModule)

//                                             most significant byte --vv
    ADD_NODE("qponmlkjihgzyxwvutsr", " 00001"); // fce8:573b:d230:ca3b 1c4e:f9d6 0632:9445
    ADD_NODE("bcdefghijklmnopqrstu", " 00002"); // fc65:9f4c:c061:84f9 2018:6e31 de3d:3bcf
    ADD_NODE("onmlkjihgzyxwvutsrqp", " 00003"); // fcbe:26ce:5c7a:9a0f 205b:358c b8f8:08bb
//                               search target --> fc01:0101:0101:0101 2101:0101 0101:0101
    ADD_NODE("mlkjihgzyxwvutsrqpon", " 00004"); // fc08:d8e6:e000:c95c 2192:d676 94f9:63a7
    ADD_NODE("lkjihgzyxwvutsrqponm", " 00005"); // fc7c:6c8d:e5ee:cf99 2f16:06c7 95ca:0c0b
    ADD_NODE("fghijklmnopqrstuvwxy", " 00006"); // fcac:3963:cbd1:6390 3e83:be89 a23f:ce66
    ADD_NODE("jihgzyxwvutsrqponmlk", " 00007"); // fc2e:3a5e:5e47:9769 4964:8f7f 3894:8c07
    ADD_NODE("kjihgzyxwvutsrqponml", " 00008"); // fc37:10aa:39ed:12bf 4a70:1507 dbe9:a054
    ADD_NODE("cdefghijklmnopqrstuv", " 00009"); // fcaa:113e:88da:d432 65f0:1c14 38d9:b656
//                                   this node --> fc39:c3ba:c711:00aa 666d:90b0 1ab6:e8c3
    ADD_NODE("rqponmlkjihgzyxwvuts", " 00010"); // fc43:41e7:2adc:d13b 78ce:1959 e4cc:c76e
    ADD_NODE("ponmlkjihgzyxwvutsrq", " 00011"); // fc83:2ab3:b65b:9ad1 7e7b:f61f e0fa:cb40
    ADD_NODE("efghijklmnopqrstuvwx", " 00012"); // fc08:0ba6:a8e2:7731 9dae:f9fd e502:767c
    ADD_NODE("abcdefghijklmnopqrst", " 00013"); // fc81:cab3:eda0:61aa 9fff:bdde 0168:f0dd
    ADD_NODE("ihgzyxwvutsrqponmlkj", " 00014"); // fc49:8fc7:7e43:981a bac1:0b5d 77fb:8818
    ADD_NODE("nmlkjihgzyxwvutsrqpo", " 00015"); // fc69:61a1:2bec:1444 bb9e:47d1 f8b3:a6a0
    ADD_NODE("defghijklmnopqrstuvw", " 00016"); // fc40:1d18:89a6:9a7e c8af:20fd 5c9f:8140
    ADD_NODE("ghijklmnopqrstuvwxyz", " 00017"); // fc74:0f2e:d77a:e5e7 cf4e:8fe9 7791:98e1


    #undef ADD_NODE

    testQuery(&outMessage, registry, allocator);
    testSearch(&outMessage, routerModule, registry, allocator);

    return 0;
}