47 Commits

Author SHA1 Message Date
idk
ea52a3251d Merge pull request #23 from i2p/macos-build-fixes
Macos build fixes
2024-02-25 15:01:14 -05:00
03954db321 add MSG_NOSIGNAL to libsam3.c 2024-02-18 13:05:52 -05:00
c8185f0ea8 add MSG_NOSIGNAL during mac pp phase 2024-02-17 10:33:42 -05:00
02b3826685 include time header 2024-02-13 12:05:00 -05:00
a71a49800f fix typo 2024-02-13 10:47:43 -05:00
3166418a2d define SOCK_NONBLOCK and SOCK_CLOEXEC for OSX" 2024-02-13 10:46:06 -05:00
b5ae6552d0 Include section needs to be true if __APPLE__ is defined 2024-02-13 10:36:37 -05:00
344c62307d It needs to go in sam3a 2024-02-13 10:31:54 -05:00
7edf37b893 that was a misidentification, use netinet/tcp instead 2024-02-13 10:24:55 -05:00
140adb2141 that was a misidentification, use netinet/tcp instead 2024-02-13 10:24:37 -05:00
b6d51e6284 since SOL_SOCKET doesn't exist on Mac, pass SOL_TCP on that platform 2024-02-13 10:17:17 -05:00
b84a3caddf Merge branch 'macos-build-fixes' of github.com:i2p/libsam3 into macos-build-fixes 2024-02-09 16:55:06 -05:00
7dbc7c1aae extern sam3atimeval2ms, sam3ams2timeval 2024-02-09 16:50:51 -05:00
idk
c38987ac1c Update src/libsam3a/libsam3a.c
Co-authored-by: Sergey Fedorov <vital.had@gmail.com>
2024-02-09 17:21:46 +00:00
92b38de9cb Remove sysinfo.h from the Apple header section 2024-02-09 10:25:48 -05:00
8b554c13b5 Include mach_time on osx platforms 2024-02-08 11:23:59 -05:00
390793bdb8 Use getpid and TickCount when on OSX platforms 2024-02-08 11:21:18 -05:00
idk
e567bb463c Update src/libsam3a/libsam3a.c
Co-authored-by: Sergey Fedorov <vital.had@gmail.com>
2024-02-08 16:21:56 +00:00
idk
883932c073 Update src/libsam3/libsam3.c
Co-authored-by: Sergey Fedorov <vital.had@gmail.com>
2024-02-08 16:21:24 +00:00
64d85291fd Disable use of sysinfo.h on Mac OSX and replace deprecated functions that killed it 2024-02-07 11:44:43 -05:00
6bee253ca6 Use PID/TickCount for random nickname string on __APPLE__ Platforms 2024-02-07 11:34:39 -05:00
94478efec2 Fix some of the headers to make progress on fixing OSX builds 2023-12-22 12:04:24 -05:00
idk
2226ef0a20 Merge branch 'MITLicense' into 'master'
Replace License that Prominently Features an Expletive

See merge request i2p-hackers/libsam3!2
2023-07-24 23:03:12 +00:00
cd24279c2a Replace License that Prominently Features an Expletive
The original license prominently features an expletive in the
license name.

Replace this license with a similar permissive license (the MIT
license was choosen in this case).

Signed-off-by: obscuratus <obscuratus@mail.i2p>
2023-07-24 22:45:30 +00:00
idk
35754667d8 Merge branch 'datagram-example' into 'master'
Fixes for Datagram Example

See merge request i2p-hackers/libsam3!1
2023-07-18 19:41:23 +00:00
4843b0b624 Fixes for Datagram Example
The datagram examples (server and client) had accumulated a few
issues preventing them from running successfully.

The examples had not been updated to handle the longer destination
key sizes utilized by the new signature type.

Also, there was misalignment in parenthesis in the datagram
server example when evaluating the 'quit' message.

Signed-off-by: obscuratus <obscuratus@mail.i2p>
2022-08-16 16:18:23 -05:00
idk
27fabf8a82 fix out-of-bounds sig, closes #2, thanks @obscuratus 2022-08-07 23:26:15 -04:00
idk
36528099fd check in fix from @obscuratus, thanks for the MR, closes #1 2022-08-07 23:23:27 -04:00
idk
3b004ee4c7 add note to non-functioning boost example 2022-06-28 15:37:19 -04:00
idk
1920a37572 fix missing signature type in sam3CreateSession DESTINATION GENERATE 2022-06-28 15:36:11 -04:00
idk
ebf7d0b012 Merge pull request #16 from i2p/generateKeys
fix public key out put in generateKeys
2020-12-13 13:51:33 +00:00
idk
b410da5986 add new examples/tests 2020-12-13 01:01:44 -05:00
idk
1b7b8cf8ba add new examples/tests 2020-12-13 01:00:46 -05:00
idk
9ca783a022 fix public key out put in generateKeys 2020-12-13 00:57:13 -05:00
idk
8623304b62 FORWARD is different from CONNECT and ACCEPT (#14) 2020-11-24 18:12:26 +00:00
idk
3f14a30065 clang-fmt 2020-11-24 13:12:07 -05:00
idk
ce0d1bfdfa FORWARD is different from CONNECT and ACCEPT 2020-11-24 13:09:52 -05:00
idk
749519ab1f Merge pull request #13 from i2p/remember-c
don't check for a correct reply on silent sessions
2020-11-24 17:43:46 +00:00
idk
a04bb557c7 don't check for a correct reply 2020-11-24 12:38:20 -05:00
idk
4bcaa17adb Merge pull request #12 from i2p/remember-c
do the checkIsSilent better
2020-11-24 17:15:18 +00:00
idk
ca20286c6b do the checkIsSilent better 2020-11-24 12:01:34 -05:00
idk
0aebf5a20a Merge pull request #11 from i2p/remember-c
Fix initialization of 'silent' *char
2020-11-23 23:28:08 +00:00
idk
baf1b3e580 clang-fmt 2020-11-23 15:01:07 -05:00
idk
e6b8f5e231 No, it needs to me a regular array not a string literal 2020-11-23 15:00:19 -05:00
idk
b324eb1e21 add examples to test silent sessions 2020-11-23 14:53:23 -05:00
idk
610e6c106e Fix initialization of 'silent' *char 2020-11-23 14:39:00 -05:00
idk
03ccfe263b Merge pull request #9 from i2p/windows-libsam3
Adds support for Windows to both libsam and libsam3a.
2020-11-20 19:42:51 +00:00
21 changed files with 742 additions and 186 deletions

11
.gitignore vendored
View File

@ -1,3 +1,14 @@
*.o
libsam3-tests
*.a
examples/libsam3
examples/sam3/dgrams
examples/sam3/dgramc
examples/sam3/keys
examples/sam3/keysp
examples/sam3namelookup
examples/sam3/streamss
examples/sam3/streamcs
examples/sam3/log
examples/sam3/err

View File

@ -32,6 +32,10 @@ libsam3-tests: ${TEST_OBJS} ${LIB}
clean:
rm -f libsam3-tests ${LIB} ${OBJS} examples/sam3/samtest
# TODO: this does not work yet because I don't know how to do it.
boost:
gcc -Werror -Wall -Wextra -Wno-unused-parameter -std=c++11 -g -lboost_system -lboost_thread -lpthread examples/boost/boost.cpp -o boost
%.o: %.c Makefile
${CC} ${CFLAGS} $(LDFLAGS) -c $< -o $@

View File

@ -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,8 +22,20 @@ 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
keysp:
${CXX} ${CFLAGS} keys.cc -o keysp ../libsam3/libsam3.o
keys:
${CC} ${CFLAGS} keys.c -o keys ../libsam3/libsam3.o
clean:
rm -f samtest lookup dgramc dgrams streamc streams streams.key test-lookup
rm -f samtest lookup dgramc dgrams streamc streams streams.key test-lookup keys keysp
debug:
sed -i 's|// libsam3_debug = 1;|libsam3_debug = 1;|g' *.c

View File

@ -1,12 +1,28 @@
/* 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.
/*
* Copyright © 2023 I2P
*
* I2P-Bote:
* 5m77dFKGEq6~7jgtrfw56q3t~SmfwZubmGdyOLQOPoPp8MYwsZ~pfUCwud6LB1EmFxkm4C3CGlzq-hVs9WnhUV
* we are the Borg. */
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the “Software”), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://git.idk.i2p/i2p-hackers/libsam3/
*/
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
@ -25,8 +41,9 @@
int main(int argc, char *argv[]) {
Sam3Session ses;
char buf[1024];
char destkey[517] = {0}; // 516 chars + \0
char destkey[SAM3_PUBKEY_SIZE + SAM3_CERT_SIZE + 1] = {0};
int sz;
size_t sizeread;
//
libsam3_debug = 1;
//
@ -34,17 +51,27 @@ int main(int argc, char *argv[]) {
FILE *fl = fopen(KEYFILE, "rb");
//
if (fl != NULL) {
if (fread(destkey, 516, 1, fl) == 1) {
fprintf(stderr, "Reading key file...\n");
sizeread = fread(destkey, sizeof(char), sizeof(destkey), fl);
fprintf(stderr, "Read %li bytes\n", sizeread);
if (ferror(fl) != 0) {
fprintf(stderr, "I/O Error\n");
return 1;
}
// Insure that the bytes read safely fits into destkey
if (sizeread == sizeof(destkey)) {
fprintf(stderr, "Error, key file is to large (> %li)\n", sizeread);
fclose(fl);
goto ok;
return 1;
}
fclose(fl);
goto ok;
}
printf("usage: dgramc PUBKEY\n");
return 1;
} else {
if (strlen(argv[1]) != 516) {
fprintf(stderr, "FATAL: invalid key length!\n");
if (strlen(argv[1]) > (SAM3_PUBKEY_SIZE + SAM3_CERT_SIZE)) {
fprintf(stderr, "FATAL: invalid key length (%li)!\n", strlen(argv[1]));
return 1;
}
strcpy(destkey, argv[1]);

View File

@ -1,12 +1,28 @@
/* 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.
/*
* Copyright © 2023 I2P
*
* I2P-Bote:
* 5m77dFKGEq6~7jgtrfw56q3t~SmfwZubmGdyOLQOPoPp8MYwsZ~pfUCwud6LB1EmFxkm4C3CGlzq-hVs9WnhUV
* we are the Borg. */
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the “Software”), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://git.idk.i2p/i2p-hackers/libsam3/
*/
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
@ -19,7 +35,9 @@
int main(int argc, char *argv[]) {
Sam3Session ses;
char privkey[1024], pubkey[1024], buf[33 * 1024];
char privkey[SAM3_PRIVKEY_MAX_SIZE + 1],
pubkey[SAM3_PUBKEY_SIZE + SAM3_CERT_SIZE + 1],
buf[33 * 1024];
/** quit command */
const char *quitstr = "quit";
@ -46,7 +64,7 @@ int main(int argc, char *argv[]) {
/** create sam session */
printf("creating session...\n");
if (sam3CreateSession(&ses, SAM3_HOST_DEFAULT, SAM3_PORT_DEFAULT, privkey,
SAM3_SESSION_DGRAM, 5, NULL) < 0) {
SAM3_SESSION_DGRAM, 4, NULL) < 0) {
fprintf(stderr, "FATAL: can't create session\n");
return 1;
}
@ -58,7 +76,8 @@ int main(int argc, char *argv[]) {
return 1;
}
/** print destination to stdout */
printf("PUB KEY\n=======\n%s\n=======\n", ses.pubkey);
printf("PUB KEY (length = %li)\n=======\n%s\n=======\n",
strlen(ses.pubkey), ses.pubkey);
if ((fl = fopen(KEYFILE, "wb")) != NULL) {
/** write public key to keyfile */
fwrite(pubkey, strlen(pubkey), 1, fl);
@ -74,7 +93,8 @@ int main(int argc, char *argv[]) {
int sz, isquit;
printf("waiting for datagram...\n");
/** blocks until we get a UDP packet */
if ((sz = sam3DatagramReceive(&ses, datagramBuf, datagramMaxLen) < 0)) {
sz = sam3DatagramReceive(&ses, datagramBuf, datagramMaxLen);
if (sz < 0) {
fprintf(stderr, "ERROR: %s\n", ses.error);
goto error;
}

20
examples/sam3/keys.c Normal file
View File

@ -0,0 +1,20 @@
//#include <string>
//#include <iostream>
#include "../libsam3/libsam3.h"
#include <stdio.h>
int main() {
// The session is only usef for transporting the data
Sam3Session ss;
if (0 > sam3GenerateKeys(&ss, SAM3_HOST_DEFAULT, SAM3_PORT_DEFAULT, 4)) {
printf("got error");
return -1;
}
printf("\tpubkey: %s \n \tprivkey: %s", ss.pubkey, ss.privkey);
/*auto pub = std::string(ss.pubkey);
auto priv = std::string(ss.privkey);
std::cout << "pub " << pub << std::endl << "priv " << priv << std::endl;*/
return 0;
}

19
examples/sam3/keys.cc Normal file
View File

@ -0,0 +1,19 @@
#include <string>
#include <iostream>
#include <stdio.h>
#include "../libsam3/libsam3.h"
int main() {
// The session is only usef for transporting the data
Sam3Session ss;
if (0 > sam3GenerateKeys(&ss, SAM3_HOST_DEFAULT, SAM3_PORT_DEFAULT, Sam3SigType::EdDSA_SHA512_Ed25519)) {
printf("got error");
return -1;
}
auto pub = std::string(ss.pubkey);
auto priv = std::string(ss.privkey);
std::cout << "pub " << pub << std::endl << "priv " << priv << std::endl;
return 0;
}

View File

@ -1,12 +1,28 @@
/* 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.
/*
* Copyright © 2023 I2P
*
* I2P-Bote:
* 5m77dFKGEq6~7jgtrfw56q3t~SmfwZubmGdyOLQOPoPp8MYwsZ~pfUCwud6LB1EmFxkm4C3CGlzq-hVs9WnhUV
* we are the Borg. */
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the “Software”), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://git.idk.i2p/i2p-hackers/libsam3/
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

View File

@ -1,12 +1,28 @@
/* 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.
/*
* Copyright © 2023 I2P
*
* I2P-Bote:
* 5m77dFKGEq6~7jgtrfw56q3t~SmfwZubmGdyOLQOPoPp8MYwsZ~pfUCwud6LB1EmFxkm4C3CGlzq-hVs9WnhUV
* we are the Borg. */
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the “Software”), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://git.idk.i2p/i2p-hackers/libsam3/
*/
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>

View File

@ -1,12 +1,28 @@
/* 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.
/*
* Copyright © 2023 I2P
*
* I2P-Bote:
* 5m77dFKGEq6~7jgtrfw56q3t~SmfwZubmGdyOLQOPoPp8MYwsZ~pfUCwud6LB1EmFxkm4C3CGlzq-hVs9WnhUV
* we are the Borg. */
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the “Software”), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://git.idk.i2p/i2p-hackers/libsam3/
*/
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>

103
examples/sam3/streamcs.c Normal file
View File

@ -0,0 +1,103 @@
/*
* Copyright © 2023 I2P
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the “Software”), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://git.idk.i2p/i2p-hackers/libsam3/
*/
#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;
}

View File

@ -1,12 +1,28 @@
/* 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.
/*
* Copyright © 2023 I2P
*
* I2P-Bote:
* 5m77dFKGEq6~7jgtrfw56q3t~SmfwZubmGdyOLQOPoPp8MYwsZ~pfUCwud6LB1EmFxkm4C3CGlzq-hVs9WnhUV
* we are the Borg. */
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the “Software”), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://git.idk.i2p/i2p-hackers/libsam3/
*/
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>

88
examples/sam3/streamss.c Normal file
View File

@ -0,0 +1,88 @@
/*
* Copyright © 2023 I2P
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the “Software”), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://git.idk.i2p/i2p-hackers/libsam3/
*/
#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;
}

View File

@ -1,12 +1,28 @@
/* 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.
/*
* Copyright © 2023 I2P
*
* I2P-Bote:
* 5m77dFKGEq6~7jgtrfw56q3t~SmfwZubmGdyOLQOPoPp8MYwsZ~pfUCwud6LB1EmFxkm4C3CGlzq-hVs9WnhUV
* we are the Borg. */
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the “Software”), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://git.idk.i2p/i2p-hackers/libsam3/
*/
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>

View File

@ -1,12 +1,28 @@
/* 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.
/*
* Copyright © 2023 I2P
*
* I2P-Bote:
* 5m77dFKGEq6~7jgtrfw56q3t~SmfwZubmGdyOLQOPoPp8MYwsZ~pfUCwud6LB1EmFxkm4C3CGlzq-hVs9WnhUV
* we are the Borg. */
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the “Software”), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://git.idk.i2p/i2p-hackers/libsam3/
*/
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>

View File

@ -1,12 +1,28 @@
/* 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.
/*
* Copyright © 2023 I2P
*
* I2P-Bote:
* 5m77dFKGEq6~7jgtrfw56q3t~SmfwZubmGdyOLQOPoPp8MYwsZ~pfUCwud6LB1EmFxkm4C3CGlzq-hVs9WnhUV
* we are the Borg. */
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the “Software”), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://git.idk.i2p/i2p-hackers/libsam3/
*/
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>

View File

@ -1,12 +1,28 @@
/* 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.
/*
* Copyright © 2023 I2P
*
* I2P-Bote:
* 5m77dFKGEq6~7jgtrfw56q3t~SmfwZubmGdyOLQOPoPp8MYwsZ~pfUCwud6LB1EmFxkm4C3CGlzq-hVs9WnhUV
* we are the Borg. */
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the “Software”), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://git.idk.i2p/i2p-hackers/libsam3/
*/
#include "libsam3.h"
#include <ctype.h>
@ -32,14 +48,31 @@
#endif
#endif
#ifdef __unix__
#if defined(__unix__) || defined(__APPLE__)
#include <arpa/inet.h>
#include <netdb.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/sysinfo.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#endif
#if defined(__unix__) && !defined(__APPLE__)
#include <sys/sysinfo.h>
#endif
#if defined(__APPLE__)
#ifndef MSG_NOSIGNAL
#define MSG_NOSIGNAL 0
#endif
#include <mach/mach_time.h>
uint32_t TickCount() {
uint64_t mat = mach_absolute_time();
uint32_t mul = 0x80d9594e;
return ((((0xffffffff & mat) * mul) >> 32) + (mat >> 32) * mul) >> 23;
}
#endif
////////////////////////////////////////////////////////////////////////////////
int libsam3_debug = 0;
@ -609,8 +642,10 @@ static inline uint32_t hashint(uint32_t a) {
}
static uint32_t genSeed(void) {
volatile uint32_t seed = 1;
uint32_t res;
#ifndef WIN32
#ifndef __APPLE__
struct sysinfo sy;
pid_t pid = getpid();
//
@ -618,10 +653,16 @@ static uint32_t genSeed(void) {
res = hashint((uint32_t)pid) ^ hashint((uint32_t)time(NULL)) ^
hashint((uint32_t)sy.sharedram) ^ hashint((uint32_t)sy.bufferram) ^
hashint((uint32_t)sy.uptime);
#else
res = hashint((uint32_t)getpid()) ^
hashint((uint32_t)TickCount());
#endif
#else
res = hashint((uint32_t)GetCurrentProcessId()) ^
hashint((uint32_t)GetTickCount());
#endif
res += __sync_fetch_and_add(&seed, 1);
//
return hashint(res);
}
@ -716,20 +757,23 @@ int sam3GenerateKeys(Sam3Session *ses, const char *hostname, int port,
return -1;
}
//
if (sam3tcpPrintf(fd, "DEST GENERATE %s\n", sigtypes[sigType]) >= 0) {
if ((rep = sam3ReadReply(fd)) != NULL &&
sam3IsGoodReply(rep, "DEST", "REPLY", NULL, NULL)) {
const char *pub = sam3FindField(rep, "PUB"),
*priv = sam3FindField(rep, "PRIV");
//
if (pub != NULL && sam3CheckValidKeyLength(pub) && priv != NULL &&
strlen(priv) >= SAM3_PRIVKEY_MIN_SIZE) {
if (sam3tcpPrintf(fd, "DEST GENERATE %s\n", sigtypes[(int)sigType]) < 0) {
strcpyerr(ses, "DEST_ERROR");
}
rep = sam3ReadReply(fd);
// sam3DumpFieldList(rep);
if (!sam3IsGoodReply(rep, "DEST", "REPLY", "PUB", NULL)) {
strcpyerr(ses, "PUBKEY_ERROR");
}
if (!sam3IsGoodReply(rep, "DEST", "REPLY", "PRIV", NULL)) {
strcpyerr(ses, "PRIVKEY_ERROR");
}
const char *pub = sam3FindField(rep, "PUB");
strcpy(ses->pubkey, pub);
const char *priv = sam3FindField(rep, "PRIV");
strcpy(ses->privkey, priv);
res = 0;
}
}
}
//
sam3FreeFieldList(rep);
sam3tcpDisconnect(fd);
@ -893,6 +937,10 @@ int sam3CreateSession(Sam3Session *ses, const char *hostname, int port,
goto error;
}
// save our keys
if (strlen(v) > SAM3_PRIVKEY_MAX_SIZE) {
fprintf(stderr, "ERROR, Unexpected key size (%li)!\n", strlen(v));
goto error;
}
strcpy(ses->privkey, v);
sam3FreeFieldList(rep);
// get public key
@ -949,11 +997,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,6 +1007,7 @@ Sam3Connection *sam3StreamConnect(Sam3Session *ses, const char *destkey) {
strcpyerr(ses, "IO_ERROR");
goto error;
}
if (!ses->silent) {
if (!sam3IsGoodReply(rep, "STREAM", "STATUS", "RESULT", "OK")) {
const char *v = sam3FindField(rep, "RESULT");
//
@ -972,6 +1019,7 @@ Sam3Connection *sam3StreamConnect(Sam3Session *ses, const char *destkey) {
// no error
strcpyerr(ses, NULL);
}
}
sam3FreeFieldList(rep);
if (conn != NULL) {
strcpy(conn->destkey, destkey);
@ -1018,12 +1066,14 @@ Sam3Connection *sam3StreamAccept(Sam3Session *ses) {
strcpyerr(ses, "IO_ERROR_RP");
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");
goto error;
@ -1056,11 +1106,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 +1134,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;
}
@ -1135,11 +1183,12 @@ int sam3DatagramSend(Sam3Session *ses, const char *destkey, const void *buf,
strcpyerr(ses, "INVALID_DATA");
return -1;
}
dbufsz = bufsize + 4 + SAM3_PUBKEY_SIZE + 1 + strlen(ses->channel) + 1;
dbufsz = bufsize + 4 + strlen(destkey) + 1 + strlen(ses->channel) + 1;
if ((dbuf = malloc(dbufsz)) == NULL) {
strcpyerr(ses, "OUT_OF_MEMORY");
return -1;
}
memset(dbuf, 0, dbufsz);
sprintf(dbuf, "3.0 %s %s\n", ses->channel, destkey);
memcpy(dbuf + strlen(dbuf), buf, bufsize);
res = sam3udpSendToIP(ses->ip, ses->port, dbuf, dbufsz);

View File

@ -1,18 +1,34 @@
/* 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.
/*
* Copyright © 2023 I2P
*
* I2P-Bote:
* 5m77dFKGEq6~7jgtrfw56q3t~SmfwZubmGdyOLQOPoPp8MYwsZ~pfUCwud6LB1EmFxkm4C3CGlzq-hVs9WnhUV
* we are the Borg. */
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the “Software”), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://git.idk.i2p/i2p-hackers/libsam3/
*/
#ifndef LIBSAM3_H
#define LIBSAM3_H
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <sys/types.h>
#ifndef _SSIZE_T_DEFINED
#define _SSIZE_T_DEFINED
@ -39,6 +55,7 @@ extern int libsam3_debug;
#define SAM3_PUBKEY_SIZE (516)
#define SAM3_CERT_SIZE (100)
#define SAM3_PRIVKEY_MIN_SIZE (884)
#define SAM3_PRIVKEY_MAX_SIZE (1024)
////////////////////////////////////////////////////////////////////////////////
/* returns fd or -1 */
@ -136,7 +153,7 @@ typedef struct Sam3Session {
Sam3SessionType type;
Sam3SigType sigType;
int fd;
char privkey[SAM3_PRIVKEY_MIN_SIZE + 1]; // destination private key (asciiz)
char privkey[SAM3_PRIVKEY_MAX_SIZE + 1]; // destination private key (asciiz)
char pubkey[SAM3_PUBKEY_SIZE + SAM3_CERT_SIZE +
1]; // destination public key (asciiz)
char channel[66]; // name of this sam session (asciiz)
@ -205,7 +222,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

View File

@ -1,14 +1,28 @@
/* async SAMv3 library
/*
* Copyright © 2023 I2P
*
* 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.
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the “Software”), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* I2P-Bote:
* 5m77dFKGEq6~7jgtrfw56q3t~SmfwZubmGdyOLQOPoPp8MYwsZ~pfUCwud6LB1EmFxkm4C3CGlzq-hVs9WnhUV
* we are the Borg. */
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://git.idk.i2p/i2p-hackers/libsam3/
*/
#include "libsam3a.h"
#include <ctype.h>
@ -34,15 +48,39 @@
#endif
#endif
#ifdef __unix__
#if defined(__unix__) && !defined(__APPLE__)
#include <sys/sysinfo.h>
#endif
#if defined(__unix__) || defined(__APPLE__)
#include <arpa/inet.h>
#include <netdb.h>
#include <netinet/in.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/sysinfo.h>
#include <sys/types.h>
#endif
#if defined(__APPLE__)
#include <mach/mach_time.h>
#include <netinet/tcp.h>
#ifndef SOCK_CLOEXEC
#define SOCK_CLOEXEC 0
#endif
#ifndef SOCK_NONBLOCK
#include <fcntl.h>
#define SOCK_NONBLOCK O_NONBLOCK
#endif
#ifndef MSG_NOSIGNAL
#define MSG_NOSIGNAL 0
#endif
uint32_t TickCount() {
uint64_t mat = mach_absolute_time();
uint32_t mul = 0x80d9594e;
return ((((0xffffffff & mat) * mul) >> 32) + (mat >> 32) * mul) >> 23;
}
#endif
////////////////////////////////////////////////////////////////////////////////
int libsam3a_debug = 0;
@ -50,11 +88,11 @@ int libsam3a_debug = 0;
#define DEFAULT_UDP_PORT (7655)
////////////////////////////////////////////////////////////////////////////////
uint64_t sam3atimeval2ms(const struct timeval *tv) {
extern uint64_t sam3atimeval2ms(const struct timeval *tv) {
return ((uint64_t)tv->tv_sec) * 1000 + ((uint64_t)tv->tv_usec) / 1000;
}
void sam3ams2timeval(struct timeval *tv, uint64_t ms) {
extern void sam3ams2timeval(struct timeval *tv, uint64_t ms) {
tv->tv_sec = ms / 1000;
tv->tv_usec = (ms % 1000) * 1000;
}
@ -651,6 +689,7 @@ static uint32_t genSeed(void) {
volatile uint32_t seed = 1;
uint32_t res;
#ifndef WIN32
#ifndef __APPLE__
struct sysinfo sy;
pid_t pid = getpid();
//
@ -658,6 +697,10 @@ static uint32_t genSeed(void) {
res = hashint((uint32_t)pid) ^ hashint((uint32_t)time(NULL)) ^
hashint((uint32_t)sy.sharedram) ^ hashint((uint32_t)sy.bufferram) ^
hashint((uint32_t)sy.uptime);
#else
res = hashint((uint32_t)getpid()) ^
hashint((uint32_t)TickCount());
#endif
#else
res = hashint((uint32_t)GetCurrentProcessId()) ^
hashint((uint32_t)GetTickCount());

View File

@ -1,14 +1,28 @@
/* async SAMv3 library
/*
* Copyright © 2023 I2P
*
* 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.
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the “Software”), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* I2P-Bote:
* 5m77dFKGEq6~7jgtrfw56q3t~SmfwZubmGdyOLQOPoPp8MYwsZ~pfUCwud6LB1EmFxkm4C3CGlzq-hVs9WnhUV
* we are the Borg. */
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://git.idk.i2p/i2p-hackers/libsam3/
*/
#ifndef LIBSAM3A_H
#define LIBSAM3A_H
@ -17,6 +31,7 @@
#include <time.h>
#include <sys/types.h>
#include <sys/time.h>
#ifdef __MINGW32__
//#include <winsock.h>

View File

@ -1,12 +1,28 @@
/* 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.
/*
* Copyright © 2023 I2P
*
* I2P-Bote:
* 5m77dFKGEq6~7jgtrfw56q3t~SmfwZubmGdyOLQOPoPp8MYwsZ~pfUCwud6LB1EmFxkm4C3CGlzq-hVs9WnhUV
* we are the Borg. */
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the “Software”), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://git.idk.i2p/i2p-hackers/libsam3/
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>