Bladeren bron

Add a new net state to get the index and begin fields from piece messages

before we read the piece data. This can be used to test for junk earlier.
master
Richard Nyberg 19 jaren geleden
bovenliggende
commit
e025c4743a
3 gewijzigde bestanden met toevoegingen van 12 en 4 verwijderingen
  1. +9
    -4
      btpd/net.c
  2. +1
    -0
      btpd/net.h
  3. +2
    -0
      btpd/peer.h

+ 9
- 4
btpd/net.c Bestand weergeven

@@ -171,10 +171,8 @@ net_dispatch_msg(struct peer *p, const char *buf)
peer_on_cancel(p, index, begin, length);
break;
case MSG_PIECE:
index = net_read32(buf);
begin = net_read32(buf + 4);
length = p->net.msg_len - 9;
peer_on_piece(p, index, begin, length, buf + 8);
peer_on_piece(p, p->net.pc_index, p->net.pc_begin, length, buf);
break;
default:
abort();
@@ -258,9 +256,16 @@ net_state(struct peer *p, const char *buf)
if (net_dispatch_msg(p, buf) != 0)
goto bad;
net_set_state(p, BTP_MSGSIZE, 4);
} else
} else if (p->net.msg_num == MSG_PIECE)
net_set_state(p, BTP_PIECEMETA, 8);
else
net_set_state(p, BTP_MSGBODY, p->net.msg_len - 1);
break;
case BTP_PIECEMETA:
p->net.pc_index = net_read32(buf);
p->net.pc_begin = net_read32(buf + 4);
net_set_state(p, BTP_MSGBODY, p->net.msg_len - 9);
break;
case BTP_MSGBODY:
if (net_dispatch_msg(p, buf) != 0)
goto bad;


+ 1
- 0
btpd/net.h Bestand weergeven

@@ -21,6 +21,7 @@ enum net_state {
SHAKE_ID,
BTP_MSGSIZE,
BTP_MSGHEAD,
BTP_PIECEMETA,
BTP_MSGBODY
};



+ 2
- 0
btpd/peer.h Bestand weergeven

@@ -52,6 +52,8 @@ struct peer {
struct {
uint32_t msg_len;
uint8_t msg_num;
uint32_t pc_index;
uint32_t pc_begin;
enum net_state state;
size_t st_bytes;
char *buf;


Laden…
Annuleren
Opslaan