Compare commits
2 commits
305e8ad254
...
50975cd0e0
Author | SHA1 | Date | |
---|---|---|---|
50975cd0e0 | |||
68347f8b0c |
2 changed files with 18 additions and 6 deletions
|
@ -13,6 +13,8 @@ Flooder::Flooder(const Bytes& data, u64 datId, u32 seqno, Protocol* proto,
|
||||||
for(auto it=peers.begin(); it != peers.end(); ++it) {
|
for(auto it=peers.begin(); it != peers.end(); ++it) {
|
||||||
triesCount[it->id] = 0;
|
triesCount[it->id] = 0;
|
||||||
toFlood.push(FloodEvt(time(NULL), it->id));
|
toFlood.push(FloodEvt(time(NULL), it->id));
|
||||||
|
fprintf(stderr, "[DBG] Flood %lX init towards %lX\n",
|
||||||
|
datId, it->id);
|
||||||
}
|
}
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
@ -30,12 +32,14 @@ Flooder::~Flooder() {
|
||||||
|
|
||||||
void Flooder::update() {
|
void Flooder::update() {
|
||||||
while(!toFlood.empty()) {
|
while(!toFlood.empty()) {
|
||||||
const FloodEvt& evt = toFlood.top();
|
FloodEvt evt = toFlood.top();
|
||||||
if(evt.time > time(NULL)) {
|
if(evt.time > time(NULL)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
toFlood.pop();
|
toFlood.pop();
|
||||||
|
|
||||||
|
fprintf(stderr, "[DBG] Flooding to %lX\n", evt.id);
|
||||||
|
|
||||||
if(triesCount[evt.id] > csts::FLOOD_RETRIES) {
|
if(triesCount[evt.id] > csts::FLOOD_RETRIES) {
|
||||||
fprintf(stderr, "[WARNING] Could not flood to %lX: no IHave.\n",
|
fprintf(stderr, "[WARNING] Could not flood to %lX: no IHave.\n",
|
||||||
evt.id);
|
evt.id);
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
const int BUFFER_SIZE = 4096;
|
const int BUFFER_SIZE = 4096;
|
||||||
|
|
||||||
int main(void) {
|
int main(int argc, char** argv) {
|
||||||
int sock = socket(PF_INET6, SOCK_DGRAM, 0);
|
int sock = socket(PF_INET6, SOCK_DGRAM, 0);
|
||||||
if(sock < 0) {
|
if(sock < 0) {
|
||||||
perror("Could not create socket");
|
perror("Could not create socket");
|
||||||
|
@ -25,10 +25,17 @@ int main(void) {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(argc < 3) {
|
||||||
|
fprintf(stderr, "Gimmeh my port and ID!\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
int port = atoi(argv[1]);
|
||||||
|
char id = atoi(argv[2]);
|
||||||
|
|
||||||
struct sockaddr_in6 sockIn;
|
struct sockaddr_in6 sockIn;
|
||||||
memset(&sockIn, 0, sizeof(sockIn));
|
memset(&sockIn, 0, sizeof(sockIn));
|
||||||
sockIn.sin6_family = AF_INET6;
|
sockIn.sin6_family = AF_INET6;
|
||||||
sockIn.sin6_port = htons(1212);
|
sockIn.sin6_port = htons(port);
|
||||||
if(bind(sock, (struct sockaddr*)&sockIn, sizeof(sockIn))) {
|
if(bind(sock, (struct sockaddr*)&sockIn, sizeof(sockIn))) {
|
||||||
perror("Could not bind socket to port 8080");
|
perror("Could not bind socket to port 8080");
|
||||||
exit(1);
|
exit(1);
|
||||||
|
@ -37,7 +44,7 @@ int main(void) {
|
||||||
char* buffer = (char*)malloc(sizeof(char) * BUFFER_SIZE);
|
char* buffer = (char*)malloc(sizeof(char) * BUFFER_SIZE);
|
||||||
while(1) {
|
while(1) {
|
||||||
struct sockaddr fromAddr;
|
struct sockaddr fromAddr;
|
||||||
socklen_t fromAddr_len;
|
socklen_t fromAddr_len = sizeof(struct sockaddr_in6);
|
||||||
ssize_t readBytes = recvfrom(sock, buffer, BUFFER_SIZE,
|
ssize_t readBytes = recvfrom(sock, buffer, BUFFER_SIZE,
|
||||||
0, &fromAddr, &fromAddr_len);
|
0, &fromAddr, &fromAddr_len);
|
||||||
if(readBytes < 0) {
|
if(readBytes < 0) {
|
||||||
|
@ -50,15 +57,16 @@ int main(void) {
|
||||||
outPck[0] = 57;
|
outPck[0] = 57;
|
||||||
outPck[1] = 0;
|
outPck[1] = 0;
|
||||||
*(uint16_t*)(outPck+2) = htonl(10);
|
*(uint16_t*)(outPck+2) = htonl(10);
|
||||||
|
outPck[11] = id;
|
||||||
outPck[12] = 2;
|
outPck[12] = 2;
|
||||||
outPck[13] = 8;
|
outPck[13] = 8;
|
||||||
memcpy(outPck+14, buffer+4, 8);
|
memcpy(outPck+14, buffer+4, 8);
|
||||||
|
|
||||||
printf("%d\n", fromAddr.sa_family);
|
printf("%d v4=%d v6=%d\n", fromAddr.sa_family, AF_INET, AF_INET6);
|
||||||
char sAddr[54];
|
char sAddr[54];
|
||||||
struct sockaddr_in6* addr6 = (struct sockaddr_in6*)(&fromAddr);
|
struct sockaddr_in6* addr6 = (struct sockaddr_in6*)(&fromAddr);
|
||||||
inet_ntop(AF_INET6, &addr6->sin6_addr, sAddr, 54);
|
inet_ntop(AF_INET6, &addr6->sin6_addr, sAddr, 54);
|
||||||
printf("Sending [%s]:%d\n", sAddr, addr6->sin6_port);
|
printf("Sending [%s]:%d\n", sAddr, ntohs(addr6->sin6_port));
|
||||||
sendto(sock, outPck, 22, 0, &fromAddr, fromAddr_len);
|
sendto(sock, outPck, 22, 0, &fromAddr, fromAddr_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue