Skip to content

Commit

Permalink
client: send resetpeer if we run out of send buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
ambrop7 committed Jul 22, 2011
1 parent f39c5c1 commit 04da0f5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
30 changes: 26 additions & 4 deletions client/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,9 @@ static void peer_unregister_need_relay (struct peer_data *peer);
// handle a link setup failure
static void peer_reset (struct peer_data *peer);

// fees chat and sends resetpeer
static void peer_resetpeer (struct peer_data *peer);

// chat handlers
static void peer_chat_handler_error (struct peer_data *peer);
static void peer_chat_handler_message (struct peer_data *peer, uint8_t *data, int data_len);
Expand Down Expand Up @@ -1848,13 +1851,11 @@ void peer_reset (struct peer_data *peer)
}
}

void peer_chat_handler_error (struct peer_data *peer)
void peer_resetpeer (struct peer_data *peer)
{
ASSERT(peer->have_chat)
ASSERT(!peer->have_resetpeer)

peer_log(peer, BLOG_ERROR, "chat error, resetting peer");

// free chat
peer_free_chat(peer);

Expand All @@ -1876,6 +1877,16 @@ void peer_chat_handler_error (struct peer_data *peer)
peer->have_resetpeer = 1;
}

void peer_chat_handler_error (struct peer_data *peer)
{
ASSERT(peer->have_chat)
ASSERT(!peer->have_resetpeer)

peer_log(peer, BLOG_ERROR, "chat error, sending resetpeer");

peer_resetpeer(peer);
}

void peer_chat_handler_message (struct peer_data *peer, uint8_t *data, int data_len)
{
ASSERT(peer->have_chat)
Expand Down Expand Up @@ -2378,10 +2389,21 @@ static int peer_start_msg (struct peer_data *peer, void **data, int type, int le
return 0;
}

#ifdef SIMULATE_PEER_OUT_OF_BUFFER
uint8_t x;
BRandom_randomize(&x, sizeof(x));
if (x < SIMULATE_PEER_OUT_OF_BUFFER) {
peer_log(peer, BLOG_ERROR, "simulating out of buffer, sending resetpeer");
peer_resetpeer(peer);
return 0;
}
#endif

// obtain buffer location
uint8_t *packet;
if (!PeerChat_StartMessage(&peer->chat, &packet)) {
peer_log(peer, BLOG_ERROR, "cannot send message, out of buffer");
peer_log(peer, BLOG_ERROR, "cannot send message, out of buffer, sending resetpeer");
peer_resetpeer(peer);
return 0;
}

Expand Down
2 changes: 2 additions & 0 deletions client/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@
// maximum scopes
#define MAX_SCOPES 8

//#define SIMULATE_PEER_OUT_OF_BUFFER 70

struct server_flow {
PacketPassFairQueueFlow qflow;
SinglePacketBuffer encoder_buffer;
Expand Down

0 comments on commit 04da0f5

Please sign in to comment.