Skip to content

Commit

Permalink
Add support for L4
Browse files Browse the repository at this point in the history
  • Loading branch information
m1kc committed Jul 12, 2022
1 parent bb56613 commit 8b6e106
Showing 1 changed file with 29 additions and 22 deletions.
51 changes: 29 additions & 22 deletions sfn.d
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ immutable uint windowSize = 1024*64;

immutable ubyte FILE = 0x01;
immutable ubyte DONE = 0x02;
immutable ubyte FILE_WITH_MD5 = 0x03;
immutable ubyte MD5_WITH_FILE = 0x03;
immutable ubyte FILE_WITH_MD5 = 0x04;

//version = TestBarAndExit;
//version = TestNumbersAndExit;
Expand Down Expand Up @@ -218,7 +219,7 @@ void receiveFiles()
remoteDone = true;
return;
}
else if (b == FILE_WITH_MD5 || b == FILE)
else if (b == FILE_WITH_MD5 || b == MD5_WITH_FILE || b == FILE)
{
write("Receiving a file: ");
string filename = to!string(stream.readLine());
Expand All @@ -227,7 +228,7 @@ void receiveFiles()
stream.read(size);
writeln(size, " bytes");
string md5str = null;
if (b == FILE_WITH_MD5)
if (b == MD5_WITH_FILE)
{
write("md5: ");
md5str = to!string(stream.readLine());
Expand All @@ -252,6 +253,13 @@ void receiveFiles()
f.close();

if (b == FILE_WITH_MD5)
{
write("md5: ");
md5str = to!string(stream.readLine());
writeln(md5str);
}

if (b == FILE_WITH_MD5 || b == MD5_WITH_FILE)
{
writeln("Checking integrity...");

Expand Down Expand Up @@ -294,37 +302,36 @@ void sendFiles()
stream.writeString("\n");
stream.write(f.size());
writeln(to!string(f.size()) ~ " bytes");

MD5 md5;
md5.start();

ulong size = f.size();
ulong sent = 0;
long time = currentTime();
foreach (ubyte[] b; f.byChunk(windowSize))
{
md5.put(b);
stream.write(b);
sent += b.length;
showBar(sent, size, time);
}
writeln();

if (!disableMD5)
{
write("md5: ");
MD5 md5;
md5.start();
foreach (ubyte[] b; f.byChunk(256*1024))
{
md5.put(b);
}
string md5str = toHexString(md5.finish());
md5str = md5str.toLower();
writeln(md5str);
stream.writeString(md5str);
stream.writeString("\n");
f.seek(0);
}
else
{
writeln("Notice: integrity check is disabled.");
}

ulong size = f.size();
ulong sent = 0;
long time = currentTime();
foreach (ubyte[] b; f.byChunk(windowSize))
{
stream.write(b);
sent += b.length;
showBar(sent, size, time);
}
writeln();
writeln("Done.");
f.close();
}
Expand All @@ -348,8 +355,8 @@ void extIP()
SocketStream ss = new SocketStream(sock);

ss.writeString(
"GET /services/simple/getip.php HTTP/1.0\r\n"
"Host: tomclaw.com\r\n"
"GET /services/simple/getip.php HTTP/1.0\r\n" ~
"Host: tomclaw.com\r\n" ~
"\r\n"
);

Expand Down

0 comments on commit 8b6e106

Please sign in to comment.