Ejemplo n.º 1
0
uint32_t crypto777_broadcast(struct crypto777_node *nn,uint8_t *msg,int32_t len,int32_t leverage,uint64_t dest64bits)
{
    uint32_t timestamp,crc = 0;
    struct SaMhdr *hdr;
    struct crypto777_packet *send;
    timestamp = 0;
    for (; len<SAM_HASH_SIZE; len++)
        msg[len] = 0;
    if ( (send = crypto777_packet(&nn->broadcast,&timestamp,(uint8_t *)msg,len,leverage,1000,dest64bits)) != 0 )
    {
        hdr = (struct SaMhdr *)send->origmsg;
        crc = _crc32(0,send->origmsg,send->origlen+sizeof(struct SaMhdr));
        //printf("crypto777_broadcast crc.%u send time.%u nonce.%u leverage.%d numrounds.%d\n",crc,hdr->timestamp,hdr->nonce,hdr->leverage,hdr->numrounds);
        //usleep((rand() % 1000000) + 100000);
        crypto777_send(0,send->origmsg,send->origlen+sizeof(struct SaMhdr),0,&nn->transport);
        free(send);
    } else crc = 0;//, printf("error broadcasting packet from %s\n",nn->email);
    return(crc);
}
Ejemplo n.º 2
0
struct crypto777_packet *nanorecv(int32_t *lenp,struct crypto777_node *nn,int32_t sock,int32_t peerid)
{
    uint32_t timestamp = 0;
    struct crypto777_packet *recv;
    uint8_t *buf = 0;
    *lenp = nn_recv(sock,&buf,NN_MSG,0);
    if ( *lenp >= 0 )
    {
        numpackets++, Totalrecv++;
        nn->recvcount++;
        if ( (recv= crypto777_packet(&nn->broadcast,&timestamp,(uint8_t *)buf,*lenp,0,0,0)) != 0 )
        {
            //printf("(%s): broadcast RECEIVED %d | (%s) recv.%d total.%ld\n",nn->ip_port,*lenp,&buf[sizeof(struct SaMhdr)],recv->recvlen,Totalrecv);
            recv->nodeid = peerid;
            return(recv);
        }
        else printf("ERROR: (%s): recv.%d total.%ld\n",nn->ip_port,*lenp,Totalrecv);
    }
    return(0);
}
Ejemplo n.º 3
0
void crypto777_processpacket(uint8_t *buf,int32_t len,struct crypto777_node *nn,char *type,char *senderip,uint16_t senderport)
{
    uint32_t timestamp = 0;
    struct crypto777_node *peer;
    struct crypto777_packet *recv;
    if ( nn != 0 )
    {
        if ( (peer= crypto777_findpeer(nn,-1,type,senderip,senderport)) == 0 )
        {
            numpackets++, Totalrecv++;
            nn->recvcount++;
            //SETBIT(Recvmasks[nn->nodeid],peer->nodeid);
            if ( (recv= crypto777_packet(&nn->broadcast,&timestamp,buf,len,0,0,0)) != 0 )
            {
                recv->nodeid = peer->nodeid;
                printf("(%s): broadcast RECEIVED %d | (%s) recv.%d total.%ld\n",nn->email,len,&buf[sizeof(struct SaMhdr)],recv->recvlen,Totalrecv);
                queue_enqueue("recvQ",&nn->recvQ,&recv->DL);
            }
            else printf("ERROR: (%s): recv.%d total.%ld\n",nn->email,len,Totalrecv);
        }
    } else printf("crypto777_processpacket got null nn: %s:%d len.%d\n",senderip,senderport,len);
}