Skip to content

Commit

Permalink
small linux related changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ig-or committed Sep 17, 2023
1 parent 8795f86 commit 5f75bbf
Show file tree
Hide file tree
Showing 7 changed files with 196 additions and 70 deletions.
55 changes: 55 additions & 0 deletions docs/networks.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,60 @@ route add 192.168.0.177 mask 255.255.255.255 192.168.8.10 if 18
to print out interface id's in Windows: route print


Jetson iptables
------------------------------
almost everywhere, eth0 to teensy interface is "WAN", wlan0 is "LAN"
https://serverfault.com/questions/564866/how-to-set-up-linux-server-as-a-router-with-nat

systemctl enable networkd-dispatcher.service from https://askubuntu.com/questions/1256921/cant-get-networkd-dispatcher-scripts-working
https://ittricks.ru/administrirovanie/linux/531/iptables-poryadok-proxozhdeniya-tablic-i-cepochek

---------------------------------------------------------------------------------
jetson iptables:
# Generated by iptables-save v1.8.4 on Sat Sep 16 20:49:44 2023
*nat
:PREROUTING ACCEPT [153:11293]
:INPUT ACCEPT [153:11293]
:OUTPUT ACCEPT [906:68481]
:POSTROUTING ACCEPT [337:24815]
:DOCKER - [0:0]
-A PREROUTING -m addrtype --dst-type LOCAL -j DOCKER
-A OUTPUT ! -d 127.0.0.0/8 -m addrtype --dst-type LOCAL -j DOCKER
-A POSTROUTING -s 172.17.0.0/16 ! -o docker0 -j MASQUERADE
-A POSTROUTING -o eth0 -j MASQUERADE
-A POSTROUTING -o wlan0 -j MASQUERADE
-A DOCKER -i docker0 -j RETURN
COMMIT
# Completed on Sat Sep 16 20:49:44 2023
# Generated by iptables-save v1.8.4 on Sat Sep 16 20:49:44 2023
*filter
:INPUT ACCEPT [90993:195069867]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [73917:26499861]
:DOCKER - [0:0]
:DOCKER-ISOLATION-STAGE-1 - [0:0]
:DOCKER-ISOLATION-STAGE-2 - [0:0]
:DOCKER-USER - [0:0]
-A FORWARD -j DOCKER-USER
-A FORWARD -j DOCKER-ISOLATION-STAGE-1
-A FORWARD -o docker0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -o docker0 -j DOCKER
-A FORWARD -i docker0 ! -o docker0 -j ACCEPT
-A FORWARD -i docker0 -o docker0 -j ACCEPT
-A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -i wlan0 -o eth0 -j ACCEPT
-A FORWARD -i eth0 -j ACCEPT
-A DOCKER-ISOLATION-STAGE-1 -i docker0 ! -o docker0 -j DOCKER-ISOLATION-STAGE-2
-A DOCKER-ISOLATION-STAGE-1 -j RETURN
-A DOCKER-ISOLATION-STAGE-2 -o docker0 -j DROP
-A DOCKER-ISOLATION-STAGE-2 -j RETURN
-A DOCKER-USER -j RETURN
COMMIT
# Completed on Sat Sep 16 20:49:44 2023







55 changes: 29 additions & 26 deletions interface/console/console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#ifdef WIN32
#include <SDKDDKVer.h>
#else
//#include <ncurses.h>
#endif

#include <stdio.h>
Expand All @@ -12,10 +14,12 @@

#include "inproc.h"
#include "eth_client.h"
#include <stdarg.h>
#include <xmroundbuf.h>

EthClient cli;
std::chrono::time_point<std::chrono::steady_clock> pingTime;
int xmprintf(const char * s, ...);

struct PingInfo {
unsigned char id;
Expand All @@ -27,11 +31,11 @@ XMRoundBuf<PingInfo, 10> pingInfo;

void teeData(char* s, int size) {
s[size] = 0;
//printf("\n teeData {%s} \n", s);
printf("%s", s);
//xmprintf("\n teeData {%s} \n", s);
xmprintf("%s", s);
}
void inpData(char* s) {
//printf(" INPDATA {%s} \n", s);
//xmprintf(" INPDATA {%s} \n", s);
cli.do_write(s);
}

Expand All @@ -46,78 +50,77 @@ void ping(unsigned char id, unsigned int time) {


int main(int argc, char *argv[]) {
//printf("starting .. ");
//xmprintf("starting .. ");
//boost::asio::io_context io_context1;
//boost::asio::ip::tcp::socket s1(io_context1);

#ifndef WIN32

#endif


using namespace std::chrono_literals;
std::thread inp(inputProc, inpData);
pingInfo.clear();
pingTime = std::chrono::steady_clock::now();
//printf("console starting .. ");
//xmprintf("console starting .. ");
//cli.startClient(teeData);
std::thread tcp([&] { cli.startClient(teeData, ping); } );
std::unique_lock<std::mutex> lk(mu);
if (cv.wait_for(lk, 1800ms, [] {return cli.connected; })) {
printf("tee\n");
xmprintf("tee\n");
} else {
printf("cannot connect to server \n");
xmprintf("cannot connect to server \n");
cli.StopClient();
std::this_thread::sleep_for(200ms);
tcp.join();
return 0;
}


std::thread inp(inputProc, inpData);


//printf("main thread started \n");
//xmprintf("main thread started \n");
while (!inpExitRequest) {
std::this_thread::sleep_for(200ms);

std::chrono::time_point<std::chrono::steady_clock> now = std::chrono::steady_clock::now();
long long dt = std::chrono::duration_cast<std::chrono::milliseconds>(now - pingTime).count() ;
if (dt > 1500) {
printf("ping timeout; dt = %llu milliseconds \r\n", dt);
xmprintf("ping timeout; dt = %llu milliseconds \r\n", dt);
inpExitRequest = true;
//printf("111 \r\n");
printf("ping times: \r\n");
//xmprintf("111 \r\n");
xmprintf("ping times: \r\n");
for (int i = 0; i < pingInfo.num; i++) {
long long dx = std::chrono::duration_cast<std::chrono::milliseconds>(now - pingInfo[i].pcTime).count();
printf("%d\t(%u, %u, %llu) \r\n", i, pingInfo[i].id, pingInfo[i].teensyTime, dx);
xmprintf("%d\t(%u, %u, %llu) \r\n", i, pingInfo[i].id, pingInfo[i].teensyTime, dx);
}

break;
}
if (!cli.connected) {
printf("server disconnected \r\n");
xmprintf("server disconnected \r\n");
break;
}
}
//printf("222 \r\n");
//xmprintf("222 \r\n");
inpExitRequest = true;
//ungetc('q', stdin);
//printf("exiting .. ");
//xmprintf("exiting .. ");
//std::cout << "exiting .. ";
//for (int i = 0; i < 250; i++) { ungetc('q', stdin); ungetc('\r', stdin); ungetc('\n', stdin); }

printf("stopping tcp .. \r\n");
xmprintf("stopping tcp .. \r\n");
cli.StopClient();
tcp.join();
printf("tcp thread finished \r\n");
xmprintf("tcp thread finished \r\n");

std::this_thread::sleep_for(200ms);
inp.join();
printf("inp thread finished \r\n");
xmprintf("inp thread finished \r\n");

printf("console stop\r\n");
xmprintf("console stop\r\n");
return 0;
}


void assert_failed(const char* file, unsigned int line, const char* str) {
printf("AF: file %s, line %d, (%s)\n", file, line, str);
xmprintf("AF: file %s, line %d, (%s)\n", file, line, str);
}

int XQSendInfo(const unsigned char* data, unsigned short int size) {
Expand Down
Loading

0 comments on commit 5f75bbf

Please sign in to comment.