Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
bytevia
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Michael Pastushkov
bytevia
Commits
0e0ac9ea
Commit
0e0ac9ea
authored
Sep 20, 2024
by
Michael Pastushkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
java work in progress
parent
6337ac45
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
227 additions
and
2 deletions
+227
-2
java/ByteVia copy.java
+225
-0
java/ByteVia$Options.class
+0
-0
java/ByteVia.class
+0
-0
java/ByteVia.java
+0
-0
run_tcp_client
+1
-1
src/bytevia.c
+1
-1
No files found.
java/ByteVia copy.java
0 → 100644
View file @
0e0ac9ea
/*
* Copyright (C) 2024 Michael Pastushkov <michael@pastushkov.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*
*/
import
java.net.*
;
import
java.io.*
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
public
class
ByteVia
{
private
static
final
int
MAX_UDP_CLIENTS
=
10
;
private
byte
[]
cipher
=
new
byte
[
256
];
private
int
cipherTime
;
private
Options
options
=
new
Options
();
private
DatagramSocket
udpSocket
;
private
ServerSocket
tcpSocket
;
private
Map
<
InetAddress
,
Integer
>
clients
=
new
HashMap
<>();
public
static
void
main
(
String
[]
args
)
{
ByteVia
server
=
new
ByteVia
();
server
.
initOptions
();
server
.
run
();
}
public
void
initOptions
()
{
// Initialize default options
options
.
localPort
=
1948
;
options
.
bindAddress
=
"0.0.0.0"
;
options
.
remoteHost
=
"p4pn.net"
;
options
.
remotePort
=
1984
;
options
.
bufferSize
=
4096
;
options
.
encrypt
=
false
;
options
.
log
=
true
;
options
.
secret
=
52341
;
options
.
proto
=
"tcp"
;
options
.
mode
=
"client"
;
}
public
void
run
()
{
try
{
if
(
options
.
log
)
{
System
.
out
.
println
(
"NetVia Java"
);
System
.
out
.
println
(
" proto: "
+
options
.
proto
);
System
.
out
.
println
(
" local: "
+
options
.
bindAddress
+
":"
+
options
.
localPort
);
System
.
out
.
println
(
" remote: "
+
options
.
remoteHost
+
":"
+
options
.
remotePort
);
System
.
out
.
println
(
" mode: "
+
options
.
mode
);
System
.
out
.
println
(
" encrypt: "
+
options
.
encrypt
);
}
if
(
options
.
proto
==
"udp"
)
{
udpSocket
=
new
DatagramSocket
(
options
.
localPort
);
System
.
out
.
println
(
"UDP server started on port "
+
options
.
localPort
);
udpServerLoop
();
}
else
{
tcpSocket
=
new
ServerSocket
(
options
.
localPort
);
System
.
out
.
println
(
"TCP server started on port "
+
options
.
localPort
);
tcpServerLoop
();
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
private
void
udpServerLoop
()
{
byte
[]
buffer
=
new
byte
[
options
.
bufferSize
];
DatagramPacket
packet
=
new
DatagramPacket
(
buffer
,
buffer
.
length
);
while
(
true
)
{
try
{
udpSocket
.
receive
(
packet
);
InetAddress
clientAddress
=
packet
.
getAddress
();
int
clientPort
=
packet
.
getPort
();
System
.
out
.
println
(
getCurrentTimestamp
()
+
" Received packet from "
+
clientAddress
);
// Add client to list if not already
if
(!
clients
.
containsKey
(
clientAddress
))
{
clients
.
put
(
clientAddress
,
clientPort
);
}
// Process data (encryption simulation)
if
(
options
.
encrypt
)
{
updateCipher
();
for
(
int
i
=
0
;
i
<
packet
.
getLength
();
i
++)
{
buffer
[
i
]
=
cipher
[
buffer
[
i
]
&
0xFF
];
}
}
// Echo back the processed data
DatagramPacket
response
=
new
DatagramPacket
(
buffer
,
packet
.
getLength
(),
clientAddress
,
clientPort
);
udpSocket
.
send
(
response
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
private
void
tcpServerLoop
()
{
while
(
true
)
{
try
{
Socket
clientSocket
=
tcpSocket
.
accept
();
System
.
out
.
println
(
getCurrentTimestamp
()
+
" Accepted connection from "
+
clientSocket
.
getInetAddress
());
new
Thread
(()
->
handleTcpClient
(
clientSocket
)).
start
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
private
void
handleTcpClient
(
Socket
clientSocket
)
{
try
{
Socket
remoteSocket
=
new
Socket
();
remoteSocket
.
connect
(
new
InetSocketAddress
(
options
.
remoteHost
,
options
.
remotePort
));
System
.
out
.
println
(
"Connected to remote server at "
+
options
.
remoteHost
+
":"
+
options
.
remotePort
);
InputStream
in
=
clientSocket
.
getInputStream
();
OutputStream
out
=
remoteSocket
.
getOutputStream
();
InputStream
in2
=
remoteSocket
.
getInputStream
();
OutputStream
out2
=
clientSocket
.
getOutputStream
();
byte
[]
buffer
=
new
byte
[
options
.
bufferSize
];
int
bytesRead
;
while
(
true
)
{
if
(
in
.
available
()
>
0
)
{
bytesRead
=
in
.
read
(
buffer
);
if
(
bytesRead
==
-
1
)
break
;
System
.
out
.
println
(
" From client "
+
bytesRead
+
" bytes"
);
// Process data (encryption simulation)
if
(
options
.
encrypt
)
{
updateCipher
();
for
(
int
i
=
0
;
i
<
bytesRead
;
i
++)
{
buffer
[
i
]
=
cipher
[
buffer
[
i
]
&
0xFF
];
}
}
out
.
write
(
buffer
,
0
,
bytesRead
);
out
.
flush
();
System
.
out
.
println
(
" Sent"
);
}
/*******/
if
(
in2
.
available
()
>
0
)
{
bytesRead
=
in2
.
read
(
buffer
);
if
(
bytesRead
==
-
1
)
break
;
System
.
out
.
println
(
" From remote "
+
bytesRead
+
" bytes"
);
out2
.
write
(
buffer
,
0
,
bytesRead
);
out2
.
flush
();
System
.
out
.
println
(
" Sent"
);
}
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
private
void
updateCipher
()
{
int
currentTime
=
getTime
();
if
(
currentTime
==
cipherTime
)
{
return
;
}
Random
random
=
new
Random
(
currentTime
);
for
(
int
i
=
0
;
i
<
256
;
i
++)
{
cipher
[
i
]
=
(
byte
)
i
;
}
for
(
int
i
=
255
;
i
>
0
;
i
--)
{
int
j
=
random
.
nextInt
(
i
+
1
);
byte
temp
=
cipher
[
i
];
cipher
[
i
]
=
cipher
[
j
];
cipher
[
j
]
=
temp
;
}
cipherTime
=
currentTime
;
System
.
out
.
println
(
getCurrentTimestamp
()
+
" Updated cipher."
);
}
private
int
getTime
()
{
return
(
int
)
(
System
.
currentTimeMillis
()
/
(
60
*
10
*
1000
));
}
private
String
getCurrentTimestamp
()
{
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
return
sdf
.
format
(
new
Date
());
}
static
class
Options
{
int
localPort
;
String
bindAddress
;
String
remoteHost
;
int
remotePort
;
int
bufferSize
;
boolean
encrypt
;
boolean
log
;
int
secret
;
String
proto
;
String
mode
;
}
}
java/ByteVia$Options.class
View file @
0e0ac9ea
No preview for this file type
java/ByteVia.class
View file @
0e0ac9ea
No preview for this file type
java/ByteVia.java
View file @
0e0ac9ea
This diff is collapsed.
Click to expand it.
run_tcp_client
View file @
0e0ac9ea
#!/bin/sh
make clean
&&
make
&&
./bytevia
--local-port
=
1948
--remote-host
=
p4pn.net
--remote-port
=
1984
--proto
=
tcp
--encrypt
=
0
make clean
&&
make
&&
./bytevia
--local-port
=
1948
--remote-host
=
p4pn.net
--remote-port
=
1984
--proto
=
tcp
--encrypt
=
1
src/bytevia.c
View file @
0e0ac9ea
...
...
@@ -90,7 +90,7 @@ unsigned int xorshift32(unsigned int *state)
void
shuffle
(
unsigned
char
*
array
,
int
n
,
unsigned
int
seed
)
{
unsigned
int
state
=
seed
;
srand
(
seed
);
//
srand(seed);
for
(
int
i
=
n
-
1
;
i
>
0
;
i
--
)
{
int
j
=
xorshift32
(
&
state
)
%
(
i
+
1
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment