Compare commits
13 Commits
windows-li
...
v0.31.00
Author | SHA1 | Date | |
---|---|---|---|
![]() |
8623304b62 | ||
![]() |
3f14a30065 | ||
![]() |
ce0d1bfdfa | ||
![]() |
749519ab1f | ||
![]() |
a04bb557c7 | ||
![]() |
4bcaa17adb | ||
![]() |
ca20286c6b | ||
![]() |
0aebf5a20a | ||
![]() |
baf1b3e580 | ||
![]() |
e6b8f5e231 | ||
![]() |
b324eb1e21 | ||
![]() |
610e6c106e | ||
![]() |
03ccfe263b |
@@ -2,7 +2,7 @@ CFLAGS := -Wall -g -O2 -std=gnu99
|
||||
|
||||
all: clean examples
|
||||
|
||||
examples: example lookup dclient dserver sclient sserver
|
||||
examples: example lookup dclient dserver sclient sserver ssserver ssclient
|
||||
|
||||
example:
|
||||
${CC} ${CFLAGS} samtest.c -o samtest ../libsam3/libsam3.o
|
||||
@@ -22,6 +22,13 @@ sclient:
|
||||
sserver:
|
||||
${CC} ${CFLAGS} streams.c -o streams ../libsam3/libsam3.o
|
||||
|
||||
ssclient:
|
||||
${CC} ${CFLAGS} streamcs.c -o streamcs ../libsam3/libsam3.o
|
||||
|
||||
ssserver:
|
||||
${CC} ${CFLAGS} streamss.c -o streamss ../libsam3/libsam3.o
|
||||
|
||||
|
||||
clean:
|
||||
rm -f samtest lookup dgramc dgrams streamc streams streams.key test-lookup
|
||||
|
||||
|
87
examples/sam3/streamcs.c
Normal file
87
examples/sam3/streamcs.c
Normal file
@@ -0,0 +1,87 @@
|
||||
/* This program is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What The Fuck You Want
|
||||
* To Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||
*
|
||||
* I2P-Bote:
|
||||
* 5m77dFKGEq6~7jgtrfw56q3t~SmfwZubmGdyOLQOPoPp8MYwsZ~pfUCwud6LB1EmFxkm4C3CGlzq-hVs9WnhUV
|
||||
* we are the Borg. */
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "../libsam3/libsam3.h"
|
||||
|
||||
#define KEYFILE "streams.key"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
Sam3Session ses;
|
||||
Sam3Connection *conn;
|
||||
char cmd[1024], destkey[617]; // 616 chars + \0
|
||||
//
|
||||
libsam3_debug = 1;
|
||||
//
|
||||
memset(destkey, 0, sizeof(destkey));
|
||||
//
|
||||
if (argc < 2) {
|
||||
FILE *fl = fopen(KEYFILE, "rb");
|
||||
//
|
||||
if (fl != NULL) {
|
||||
if (fread(destkey, 616, 1, fl) == 1) {
|
||||
fclose(fl);
|
||||
goto ok;
|
||||
}
|
||||
fclose(fl);
|
||||
}
|
||||
printf("usage: streamc PUBKEY\n");
|
||||
return 1;
|
||||
} else {
|
||||
if (!sam3CheckValidKeyLength(argv[1])) {
|
||||
fprintf(stderr, "FATAL: invalid key length! %s %lu\n", argv[1],
|
||||
strlen(argv[1]));
|
||||
return 1;
|
||||
}
|
||||
strcpy(destkey, argv[1]);
|
||||
}
|
||||
//
|
||||
ok:
|
||||
printf("creating session...\n");
|
||||
// create TRANSIENT session
|
||||
if (sam3CreateSilentSession(&ses, SAM3_HOST_DEFAULT, SAM3_PORT_DEFAULT,
|
||||
SAM3_DESTINATION_TRANSIENT, SAM3_SESSION_STREAM,
|
||||
4, NULL) < 0) {
|
||||
fprintf(stderr, "FATAL: can't create session\n");
|
||||
return 1;
|
||||
}
|
||||
//
|
||||
printf("connecting...\n");
|
||||
if ((conn = sam3StreamConnect(&ses, destkey)) == NULL) {
|
||||
fprintf(stderr, "FATAL: can't connect: %s\n", ses.error);
|
||||
sam3CloseSession(&ses);
|
||||
return 1;
|
||||
}
|
||||
//
|
||||
// now waiting for incoming connection
|
||||
printf("sending test command...\n");
|
||||
if (sam3tcpPrintf(conn->fd, "test\n") < 0)
|
||||
goto error;
|
||||
if (sam3tcpReceiveStr(conn->fd, cmd, sizeof(cmd)) < 0)
|
||||
goto error;
|
||||
printf("echo: %s\n", cmd);
|
||||
//
|
||||
printf("sending quit command...\n");
|
||||
if (sam3tcpPrintf(conn->fd, "quit\n") < 0)
|
||||
goto error;
|
||||
//
|
||||
sam3CloseConnection(conn);
|
||||
sam3CloseSession(&ses);
|
||||
return 0;
|
||||
error:
|
||||
fprintf(stderr, "FATAL: some error occured!\n");
|
||||
sam3CloseConnection(conn);
|
||||
sam3CloseSession(&ses);
|
||||
return 1;
|
||||
}
|
72
examples/sam3/streamss.c
Normal file
72
examples/sam3/streamss.c
Normal file
@@ -0,0 +1,72 @@
|
||||
/* This program is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What The Fuck You Want
|
||||
* To Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||
*
|
||||
* I2P-Bote:
|
||||
* 5m77dFKGEq6~7jgtrfw56q3t~SmfwZubmGdyOLQOPoPp8MYwsZ~pfUCwud6LB1EmFxkm4C3CGlzq-hVs9WnhUV
|
||||
* we are the Borg. */
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "../libsam3/libsam3.h"
|
||||
|
||||
#define KEYFILE "streams.key"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
Sam3Session ses;
|
||||
Sam3Connection *conn;
|
||||
FILE *fl;
|
||||
//
|
||||
libsam3_debug = 1;
|
||||
//
|
||||
printf("creating session...\n");
|
||||
// create TRANSIENT session
|
||||
if (sam3CreateSilentSession(&ses, SAM3_HOST_DEFAULT, SAM3_PORT_DEFAULT,
|
||||
SAM3_DESTINATION_TRANSIENT, SAM3_SESSION_STREAM,
|
||||
4, NULL) < 0) {
|
||||
fprintf(stderr, "FATAL: can't create session\n");
|
||||
return 1;
|
||||
}
|
||||
//
|
||||
printf("PUB KEY\n=======\n%s\n=======\n", ses.pubkey);
|
||||
if ((fl = fopen(KEYFILE, "wb")) != NULL) {
|
||||
fwrite(ses.pubkey, strlen(ses.pubkey), 1, fl);
|
||||
fclose(fl);
|
||||
}
|
||||
//
|
||||
printf("starting stream acceptor...\n");
|
||||
if ((conn = sam3StreamAccept(&ses)) == NULL) {
|
||||
fprintf(stderr, "FATAL: can't accept: %s\n", ses.error);
|
||||
sam3CloseSession(&ses);
|
||||
return 1;
|
||||
}
|
||||
printf("FROM\n====\n%s\n====\n", conn->destkey);
|
||||
//
|
||||
printf("starting main loop...\n");
|
||||
for (;;) {
|
||||
char cmd[256];
|
||||
//
|
||||
if (sam3tcpReceiveStr(conn->fd, cmd, sizeof(cmd)) < 0)
|
||||
goto error;
|
||||
printf("cmd: [%s]\n", cmd);
|
||||
if (strcmp(cmd, "quit") == 0)
|
||||
break;
|
||||
// echo command
|
||||
if (sam3tcpPrintf(conn->fd, "re: %s\n", cmd) < 0)
|
||||
goto error;
|
||||
}
|
||||
//
|
||||
sam3CloseSession(&ses);
|
||||
unlink(KEYFILE);
|
||||
return 0;
|
||||
error:
|
||||
fprintf(stderr, "FATAL: some error occured!\n");
|
||||
sam3CloseSession(&ses);
|
||||
unlink(KEYFILE);
|
||||
return 1;
|
||||
}
|
@@ -949,11 +949,9 @@ Sam3Connection *sam3StreamConnect(Sam3Session *ses, const char *destkey) {
|
||||
strcpyerr(ses, "IO_ERROR_SK");
|
||||
goto error;
|
||||
}
|
||||
char silent[6];
|
||||
checkIsSilent(ses, silent);
|
||||
if (sam3tcpPrintf(conn->fd,
|
||||
"STREAM CONNECT ID=%s DESTINATION=%s SILENT=%s\n",
|
||||
ses->channel, destkey, silent) < 0) {
|
||||
ses->channel, destkey, checkIsSilent(ses)) < 0) {
|
||||
strcpyerr(ses, "IO_ERROR");
|
||||
goto error;
|
||||
}
|
||||
@@ -961,16 +959,18 @@ Sam3Connection *sam3StreamConnect(Sam3Session *ses, const char *destkey) {
|
||||
strcpyerr(ses, "IO_ERROR");
|
||||
goto error;
|
||||
}
|
||||
if (!sam3IsGoodReply(rep, "STREAM", "STATUS", "RESULT", "OK")) {
|
||||
const char *v = sam3FindField(rep, "RESULT");
|
||||
//
|
||||
strcpyerr(ses, (v != NULL && v[0] ? v : "I2P_ERROR"));
|
||||
sam3CloseConnectionInternal(conn);
|
||||
free(conn);
|
||||
conn = NULL;
|
||||
} else {
|
||||
// no error
|
||||
strcpyerr(ses, NULL);
|
||||
if (!ses->silent) {
|
||||
if (!sam3IsGoodReply(rep, "STREAM", "STATUS", "RESULT", "OK")) {
|
||||
const char *v = sam3FindField(rep, "RESULT");
|
||||
//
|
||||
strcpyerr(ses, (v != NULL && v[0] ? v : "I2P_ERROR"));
|
||||
sam3CloseConnectionInternal(conn);
|
||||
free(conn);
|
||||
conn = NULL;
|
||||
} else {
|
||||
// no error
|
||||
strcpyerr(ses, NULL);
|
||||
}
|
||||
}
|
||||
sam3FreeFieldList(rep);
|
||||
if (conn != NULL) {
|
||||
@@ -1018,11 +1018,13 @@ Sam3Connection *sam3StreamAccept(Sam3Session *ses) {
|
||||
strcpyerr(ses, "IO_ERROR_RP");
|
||||
goto error;
|
||||
}
|
||||
if (!sam3IsGoodReply(rep, "STREAM", "STATUS", "RESULT", "OK")) {
|
||||
const char *v = sam3FindField(rep, "RESULT");
|
||||
//
|
||||
strcpyerr(ses, (v != NULL && v[0] ? v : "I2P_ERROR_RES"));
|
||||
goto error;
|
||||
if (!ses->silent) {
|
||||
if (!sam3IsGoodReply(rep, "STREAM", "STATUS", "RESULT", "OK")) {
|
||||
const char *v = sam3FindField(rep, "RESULT");
|
||||
//
|
||||
strcpyerr(ses, (v != NULL && v[0] ? v : "I2P_ERROR_RES"));
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
if (sam3tcpReceiveStr(conn->fd, repstr, sizeof(repstr)) < 0) {
|
||||
strcpyerr(ses, "IO_ERROR_RP1");
|
||||
@@ -1056,11 +1058,11 @@ Sam3Connection *sam3StreamAccept(Sam3Session *ses) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void checkIsSilent(Sam3Session *ses, char *str) {
|
||||
const char *checkIsSilent(Sam3Session *ses) {
|
||||
if (ses->silent == true) {
|
||||
str = "true ";
|
||||
return "true";
|
||||
} else {
|
||||
str = "false";
|
||||
return "false";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1084,11 +1086,9 @@ int sam3StreamForward(Sam3Session *ses, const char *hostname, int port) {
|
||||
strcpyerr(ses, "IO_ERROR_SK");
|
||||
goto error;
|
||||
}
|
||||
char silent[6];
|
||||
checkIsSilent(ses, silent);
|
||||
if (sam3tcpPrintf(ses->fwd_fd,
|
||||
"STREAM FORWARD ID=%s PORT=%d HOST=%s SILENT=%s\n",
|
||||
ses->channel, port, hostname, silent) < 0) {
|
||||
ses->channel, port, hostname, checkIsSilent(ses)) < 0) {
|
||||
strcpyerr(ses, "IO_ERROR_PF");
|
||||
goto error;
|
||||
}
|
||||
|
@@ -205,7 +205,7 @@ extern int sam3CloseSession(Sam3Session *ses);
|
||||
* characters for use with sam3tcpPrintf() checkIsSilent
|
||||
*/
|
||||
|
||||
void checkIsSilent(Sam3Session *ses, char *str);
|
||||
const char *checkIsSilent(Sam3Session *ses);
|
||||
|
||||
/*
|
||||
* Check to make sure that the destination in use is of a valid length, returns
|
||||
|
Reference in New Issue
Block a user