Skip to content

Commit

Permalink
Merge pull request wolfSSL#17 from ejohnstown/highwater
Browse files Browse the repository at this point in the history
Transfer Highwater Mark, Session Key Refactoring
  • Loading branch information
JacobBarthelmeh committed Oct 5, 2016
2 parents 69a6fbc + 5698900 commit 7952fdf
Show file tree
Hide file tree
Showing 5 changed files with 316 additions and 168 deletions.
28 changes: 28 additions & 0 deletions examples/echoserver/echoserver.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ typedef struct {
} thread_ctx_t;


#ifndef DEFAULT_HIGHWATER_MARK
#define DEFAULT_HIGHWATER_MARK 0
#endif


#ifdef __GNUC__
#define WS_NORETURN __attribute__((noreturn))
#else
Expand Down Expand Up @@ -587,11 +592,29 @@ static int wsUserAuth(uint8_t authType,
}


static int wsHighwater(uint8_t side, void* ctx)
{
if (ctx) {
WOLFSSH* ssh = (WOLFSSH*)ctx;
uint32_t highwaterMark = wolfSSH_GetHighwater(ssh);

printf("HIGHWATER ALERT: (%u) %s\n", highwaterMark,
(side == WOLFSSH_HWSIDE_RECEIVE) ? "receive" : "transmit");
highwaterMark *= 2;
printf(" Doubling the highwater mark to %u.\n", highwaterMark);
wolfSSH_SetHighwater(ssh, highwaterMark);
}

return 0;
}


int main(void)
{
WOLFSSH_CTX* ctx = NULL;
PwMapList pwMapList;
SOCKET_T listenFd = 0;
uint32_t defaultHighwater = DEFAULT_HIGHWATER_MARK;

#ifdef DEBUG_WOLFSSH
wolfSSH_Debugging_ON();
Expand All @@ -610,6 +633,8 @@ int main(void)

memset(&pwMapList, 0, sizeof(pwMapList));
wolfSSH_SetUserAuth(ctx, wsUserAuth);
if (defaultHighwater > 0)
wolfSSH_SetHighwaterCb(ctx, defaultHighwater, wsHighwater);

{
uint8_t buf[SCRATCH_BUFFER_SIZE];
Expand Down Expand Up @@ -663,6 +688,9 @@ int main(void)
exit(EXIT_FAILURE);
}
wolfSSH_SetUserAuthCtx(ssh, &pwMapList);
/* Use the session object for its own highwater callback ctx */
if (defaultHighwater > 0)
wolfSSH_SetHighwaterCtx(ssh, (void*)ssh);

if (listen(listenFd, 5) != 0)
err_sys("tcp listen failed");
Expand Down

0 comments on commit 7952fdf

Please sign in to comment.