Skip to content

Commit

Permalink
Merge pull request #10 from tindy2013/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
tindy2013 committed Aug 24, 2019
2 parents 948a382 + 06d557b commit 40d0630
Show file tree
Hide file tree
Showing 23 changed files with 417 additions and 138 deletions.
28 changes: 14 additions & 14 deletions build.macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
mkdir obj
mkdir bin
set -e
gcc -I/usr/local/include -Wall -fexceptions -D_MACOS -DCURL_STATICLIB -g -std=c++11 -c geoip.cpp -o obj/geoip.o
gcc -I/usr/local/include -Wall -fexceptions -D_MACOS -DCURL_STATICLIB -g -std=c++11 -c logger.cpp -o obj/logger.o
gcc -I/usr/local/include -Wall -fexceptions -D_MACOS -DCURL_STATICLIB -g -std=c++11 -c main.cpp -o obj/main.o
gcc -I/usr/local/include -Wall -fexceptions -D_MACOS -DCURL_STATICLIB -g -std=c++11 -c misc.cpp -o obj/misc.o
gcc -I/usr/local/include -Wall -fexceptions -D_MACOS -DCURL_STATICLIB -g -std=c++11 -c multithread-test.cpp -o obj/multithread-test.o
gcc -I/usr/local/include -Wall -fexceptions -D_MACOS -DCURL_STATICLIB -g -std=c++11 -c printout.cpp -o obj/printout.o
gcc -I/usr/local/include -Wall -fexceptions -D_MACOS -DCURL_STATICLIB -g -std=c++11 -c processes.cpp -o obj/processes.o
gcc -I/usr/local/include -Wall -fexceptions -D_MACOS -DCURL_STATICLIB -g -std=c++11 -c renderer.cpp -o obj/renderer.o
gcc -I/usr/local/include -Wall -fexceptions -D_MACOS -DCURL_STATICLIB -g -std=c++11 -c rulematch.cpp -o obj/rulematch.o
gcc -I/usr/local/include -Wall -fexceptions -D_MACOS -DCURL_STATICLIB -g -std=c++11 -c socket.cpp -o obj/socket.o
gcc -I/usr/local/include -Wall -fexceptions -D_MACOS -DCURL_STATICLIB -g -std=c++11 -c speedtestutil.cpp -o obj/speedtestutil.o
gcc -I/usr/local/include -Wall -fexceptions -D_MACOS -DCURL_STATICLIB -g -std=c++11 -c tcping.cpp -o obj/tcping.o
gcc -I/usr/local/include -Wall -fexceptions -D_MACOS -DCURL_STATICLIB -g -std=c++11 -c webget.cpp -o obj/webget.o
g++ -g -o stairspeedtest obj/geoip.o obj/logger.o obj/main.o obj/misc.o obj/multithread-test.o obj/printout.o obj/processes.o obj/renderer.o obj/rulematch.o obj/socket.o obj/speedtestutil.o obj/tcping.o obj/webget.o -L/usr/local/lib -lcurl -lPNGwriter -lpng16 -lfreetype -lz -lssl -lcrypto -lyaml-cpp -ldl -lpthread
c++ -I/usr/local/include -Wall -fexceptions -D_MACOS -DCURL_STATICLIB -g -std=c++11 -c geoip.cpp -o obj/geoip.o
c++ -I/usr/local/include -Wall -fexceptions -D_MACOS -DCURL_STATICLIB -g -std=c++11 -c logger.cpp -o obj/logger.o
c++ -I/usr/local/include -Wall -fexceptions -D_MACOS -DCURL_STATICLIB -g -std=c++11 -c main.cpp -o obj/main.o
c++ -I/usr/local/include -Wall -fexceptions -D_MACOS -DCURL_STATICLIB -g -std=c++11 -c misc.cpp -o obj/misc.o
c++ -I/usr/local/include -Wall -fexceptions -D_MACOS -DCURL_STATICLIB -g -std=c++11 -c multithread-test.cpp -o obj/multithread-test.o
c++ -I/usr/local/include -Wall -fexceptions -D_MACOS -DCURL_STATICLIB -g -std=c++11 -c printout.cpp -o obj/printout.o
c++ -I/usr/local/include -Wall -fexceptions -D_MACOS -DCURL_STATICLIB -g -std=c++11 -c processes.cpp -o obj/processes.o
c++ -I/usr/local/include -Wall -fexceptions -D_MACOS -DCURL_STATICLIB -g -std=c++11 -c renderer.cpp -o obj/renderer.o
c++ -I/usr/local/include -Wall -fexceptions -D_MACOS -DCURL_STATICLIB -g -std=c++11 -c rulematch.cpp -o obj/rulematch.o
c++ -I/usr/local/include -Wall -fexceptions -D_MACOS -DCURL_STATICLIB -g -std=c++11 -c socket.cpp -o obj/socket.o
c++ -I/usr/local/include -Wall -fexceptions -D_MACOS -DCURL_STATICLIB -g -std=c++11 -c speedtestutil.cpp -o obj/speedtestutil.o
c++ -I/usr/local/include -Wall -fexceptions -D_MACOS -DCURL_STATICLIB -g -std=c++11 -c tcping.cpp -o obj/tcping.o
c++ -I/usr/local/include -Wall -fexceptions -D_MACOS -DCURL_STATICLIB -g -std=c++11 -c webget.cpp -o obj/webget.o
c++ -g -o stairspeedtest obj/geoip.o obj/logger.o obj/main.o obj/misc.o obj/multithread-test.o obj/printout.o obj/processes.o obj/renderer.o obj/rulematch.o obj/socket.o obj/speedtestutil.o obj/tcping.o obj/webget.o -L/usr/local/lib -lcurl -lPNGwriter -lpng16 -lfreetype -lz -lssl -lcrypto -lyaml-cpp -ldl -lpthread
chmod +x stairspeedtest

18 changes: 6 additions & 12 deletions config.macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ wget https://www.openssl.org/source/openssl-1.1.1c.tar.gz
tar xvf openssl-1.1.1c.tar.gz
cd openssl-1.1.1c
#override compiler
CC=gcc ./config --prefix=/usr/local
make -j8
CC=cc ./config --prefix=/usr/local
#don't install docs since we don't need them
sudo make install_sw -j8
#fix install error
Expand All @@ -50,25 +49,22 @@ cd ..
#tar xvf curl-7.65.1.tar.gz
#cd curl-7.65.1
#./configure --disable-shared --disable-ldap --disable-ldaps --disable-smtp --disable-pop3 --disable-rtmp --disable-imap --disable-gopher --disable-telnet --disable-tftp
#make -j8
#sudo make install -j8
#cd ..

echo downloading and compiling libpng-1.6.37
wget https://nchc.dl.sourceforge.net/project/libpng/libpng16/1.6.37/libpng-1.6.37.tar.gz
tar xvf libpng-1.6.37.tar.gz
cd libpng-1.6.37
./configure
make -j8
CC=cc ./configure
sudo make install -j8
cd ..

echo downloading and compiling freetype-2.10.1
wget https://nchc.dl.sourceforge.net/project/freetype/freetype2/2.10.1/freetype-2.10.1.tar.xz
tar xvf freetype-2.10.1.tar.xz
cd freetype-2.10.1
./configure
make -j8
CC=cc ./configure
sudo make install -j8
#a fix for incorrect file path
sudo mv /usr/local/include/freetype2/* /usr/local/include
Expand All @@ -78,8 +74,7 @@ cd ..
echo downloading and compiling pngwriter
git clone https://github.com/pngwriter/pngwriter
cd pngwriter
cmake .
make -j8
CC=cc cmake .
sudo make install -j8
#fix install error
#sudo install libPNGwriter.a /usr/local/lib/
Expand All @@ -88,8 +83,7 @@ cd ..
echo downloading and installing rapidjson
git clone https://github.com/tencent/rapidjson
cd rapidjson
cmake .
make -j8
CC=cc cmake .
sudo make install -j8
cd ..

Expand All @@ -116,7 +110,7 @@ echo downloading and compiling shadowsocksr-libev
git clone https://github.com/shadowsocksrr/shadowsocksr-libev
cd shadowsocksr-libev
#override some warning settings
CFLAGS+="-Wno-format-overflow -Wno-format-truncation -Wno-sizeof-pointer-memaccess" ./configure --with-openssl-lib=/usr/local/lib --with-openssl-include=/usr/local/include --disable-documentation
CC="cc" CFLAGS+="-Wno-format-overflow -Wno-format-truncation -Wno-sizeof-pointer-memaccess" ./configure --with-openssl-lib=/usr/local/lib --with-openssl-include=/usr/local/include --disable-documentation
make -j8
#will not directly install this one, use another method
sudo install src/ss-local /usr/local/bin/ssr-local
Expand Down
32 changes: 32 additions & 0 deletions config.termux.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash
set -e
pkg upgrade

#first install core utilities
pkg install -y git cmake clang autoconf automake libtool

#then install precompiled library from repo
pkg install -y openssl-static libcurl-static libpng-static libev-static libz-static freetype-static

#get rapidjson
git clone https://github.com/tencent/rapidjson
cd rapidjson
cmake -D CMAKE_INSTALL_PREFIX=/data/data/com.termux/files/usr .
make install -j2
cd ..

#get pngwriter
git clone https://github.com/pngwriter/pngwriter
cd pngwriter
cmake -D CMAKE_INSTALL_PREFIX=/data/data/com.termux/files/usr .
make install -j2
cd ..

#get yaml-cpp
git clone https://github.com/jbeder/yaml-cpp
cd yaml-cpp
cmake -D CMAKE_INSTALL_PREFIX=/data/data/com.termux/files/usr .
make install -j2
cd ..

echo all done!
10 changes: 10 additions & 0 deletions geoip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@
#include "webget.h"
#include "geoip.h"
#include "misc.h"
#include "logger.h"

using namespace rapidjson;

geoIPInfo getGeoIPInfo(string ip, string proxy)
{
writeLog(LOG_TYPE_GEOIP, "GeoIP parse begin.");
string strRet, address = ip;
geoIPInfo info;
Document json;

if(address == "")
{
writeLog(LOG_TYPE_GEOIP, "No address provided, getting GeoIP through proxy '" + proxy + "'.");
strRet = webGet("https://api.ip.sb/geoip", proxy);
}
else
Expand All @@ -28,17 +31,23 @@ geoIPInfo getGeoIPInfo(string ip, string proxy)
address = ip;
}
}
writeLog(LOG_TYPE_GEOIP, "Getting GeoIP of '" + address + "' through proxy '" + proxy + "'.");
strRet = webGet("https://api.ip.sb/geoip/" + address, proxy);
}
if(strRet == "")
{
writeLog(LOG_TYPE_GEOIP, "No GeoIP result. Leaving...");
return info;
}

writeLog(LOG_TYPE_GEOIP, "Parsing GeoIP result...");
json.Parse(strRet.data());

if(json.HasMember("code"))
{
if(json["code"].GetInt() == 401)
{
writeLog(LOG_TYPE_GEOIP, "Invalid address.");
return info;
}
}
Expand Down Expand Up @@ -69,6 +78,7 @@ geoIPInfo getGeoIPInfo(string ip, string proxy)
if(json.HasMember("timezone"))
info.timezone = json["timezone"].GetString();

writeLog(LOG_TYPE_GEOIP, "Parse GeoIP complete. Leaving...");
return info;
}

Expand Down
27 changes: 25 additions & 2 deletions logger.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
#include <string>
#include <fstream>
#include <sstream>

#include "logger.h"
#include "version.h"
#include "misc.h"
#include "printout.h"

#include <sys/time.h>
#ifdef _WIN32
#include <direct.h>
#else
#include <sys/types.h>
#include <sys/stat.h>
#endif // _WIN32

using namespace std;

Expand All @@ -22,7 +36,7 @@ string getTime(int type)
string format;
timeval tv;
gettimeofday(&tv, NULL);
snprintf(cMillis, 7, "%.6ld", tv.tv_usec);
snprintf(cMillis, 7, "%.6ld", (long)tv.tv_usec);
lt = time(NULL);
struct tm *local = localtime(&lt);
switch(type)
Expand Down Expand Up @@ -68,7 +82,7 @@ void resultInit(bool export_with_maxspeed)

void writeLog(int type, string content)
{
string timestr = "[" + getTime(2) + "]",typestr;
string timestr = "[" + getTime(2) + "]", typestr = "[UNKNOWN]";
switch(type)
{
case LOG_TYPE_ERROR:
Expand All @@ -80,6 +94,15 @@ void writeLog(int type, string content)
case LOG_TYPE_RAW:
typestr = "[RAW]";
break;
case LOG_TYPE_GEOIP:
typestr = "[GEOIP]";
break;
case LOG_TYPE_TCPING:
typestr = "[TCPING]";
break;
case LOG_TYPE_FILEDL:
typestr = "[FILEDL]";
break;
}
content = timestr + typestr + content;
writeToFile(logPath, content, false);
Expand Down
19 changes: 7 additions & 12 deletions logger.h
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
#ifndef LOGGER_H_INCLUDED
#define LOGGER_H_INCLUDED

#include "misc.h"
#include "printout.h"
#include <string>

#include <bits/stdc++.h>
#include <sys/time.h>
#ifdef _WIN32
#include <direct.h>
#else
#include <sys/types.h>
#include <sys/stat.h>
#endif // _WIN32
#include "misc.h"

#define LOG_TYPE_INFO 1
#define LOG_TYPE_ERROR 2
#define LOG_TYPE_RAW 3

extern string resultPath, logPath;
#define LOG_TYPE_TCPING 4
#define LOG_TYPE_FILEDL 5
#define LOG_TYPE_GEOIP 6

using namespace std;

extern string resultPath, logPath;

int makeDir(const char *path);
string getTime(int type);
void resultInit(bool export_with_maxspeed);
Expand Down
26 changes: 23 additions & 3 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#include <bits/stdc++.h>
#include <string>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <regex>
#include <fstream>
#include <iomanip>

#include "socket.h"
#include "misc.h"
Expand Down Expand Up @@ -317,6 +323,19 @@ void readConf(string path)
infile.close();
}

void signalHandler(int signum)
{
cerr << "Interrupt signal (" << signum << ") received.\n";

killClient(SPEEDTEST_MESSAGE_FOUNDSS);
killClient(SPEEDTEST_MESSAGE_FOUNDSSR);
killClient(SPEEDTEST_MESSAGE_FOUNDVMESS);
writeLog(LOG_TYPE_INFO, "Received SIGINT. Exit right now.");
logEOF();

exit(signum);
}

void chkArg(int argc, char* argv[])
{
for(int i = 0; i<argc; i++)
Expand Down Expand Up @@ -552,8 +571,9 @@ int main(int argc, char* argv[])
nodeInfo node;
string link, strSub, strInput, fileContent, strProxy;
int linkType = -1;
cout<<fixed;
cout<<setprecision(2);
cout << fixed;
cout << setprecision(2);
signal(SIGINT, signalHandler);

logInit(rpcmode);
//speedtest.bat :main
Expand Down
Loading

0 comments on commit 40d0630

Please sign in to comment.