Last Day
This commit is contained in:
parent
35177895ce
commit
cec3d71e52
2
gradle.properties
Normal file
2
gradle.properties
Normal file
@ -0,0 +1,2 @@
|
||||
org.gradle.parallel=true
|
||||
org.gradle.caching=true
|
@ -23,6 +23,8 @@ public class Main {
|
||||
});
|
||||
sfsServer.start();
|
||||
|
||||
|
||||
|
||||
Thread sftpServer = new Thread(() -> {
|
||||
try {
|
||||
System.out.println("Starting sftp server...");
|
||||
@ -31,7 +33,7 @@ public class Main {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
sftpServer.start();
|
||||
//sftpServer.start();
|
||||
|
||||
Thread httpServer = new Thread(() -> {
|
||||
try {
|
||||
@ -41,7 +43,7 @@ public class Main {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
httpServer.start();
|
||||
//httpServer.start();
|
||||
|
||||
}
|
||||
}
|
||||
|
8
src/main/java/tech/nevets/sfss/net/Connection.java
Normal file
8
src/main/java/tech/nevets/sfss/net/Connection.java
Normal file
@ -0,0 +1,8 @@
|
||||
package tech.nevets.sfss.net;
|
||||
|
||||
public class Connection {
|
||||
|
||||
public Connection() {
|
||||
|
||||
}
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
package tech.nevets.sfss.net;
|
||||
|
||||
public class SFSData {
|
||||
private final byte length;
|
||||
|
||||
public SFSData(byte[] data) {
|
||||
this.length = data[0];
|
||||
}
|
||||
|
||||
public SFSData(int length) {
|
||||
if (length > 255 || length < 0) {
|
||||
throw new IllegalArgumentException("Length outside range 0-255");
|
||||
}
|
||||
this.length = (byte) length;
|
||||
}
|
||||
|
||||
public byte getLength() {
|
||||
return length;
|
||||
}
|
||||
|
||||
public byte[] toBytes() {
|
||||
return new byte[]{
|
||||
length
|
||||
};
|
||||
}
|
||||
|
||||
}
|
@ -6,9 +6,11 @@ import javax.net.ssl.SSLServerSocket;
|
||||
import javax.net.ssl.SSLServerSocketFactory;
|
||||
import javax.net.ssl.SSLSocket;
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
public class SFSServer {
|
||||
private final SSLServerSocket serverSocket;
|
||||
private volatile boolean running = true;
|
||||
|
||||
public SFSServer(int port) throws IOException {
|
||||
SSLServerSocketFactory factory = StoreManager.getSSLContext().getServerSocketFactory();
|
||||
@ -20,6 +22,17 @@ public class SFSServer {
|
||||
serverSocket.setNeedClientAuth(false);
|
||||
serverSocket.setWantClientAuth(false);
|
||||
|
||||
SSLSocket s = (SSLSocket) serverSocket.accept();
|
||||
while(running) {
|
||||
SSLSocket conn = (SSLSocket) serverSocket.accept();
|
||||
conn.getChannel();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isRunning() {
|
||||
return running;
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
running = false;
|
||||
}
|
||||
}
|
||||
|
16
src/main/java/tech/nevets/sfss/net/packets/SFSData.java
Normal file
16
src/main/java/tech/nevets/sfss/net/packets/SFSData.java
Normal file
@ -0,0 +1,16 @@
|
||||
package tech.nevets.sfss.net.packets;
|
||||
|
||||
import java.net.DatagramPacket;
|
||||
|
||||
public class SFSData {
|
||||
|
||||
private final DatagramPacket packet;
|
||||
|
||||
public SFSData(DatagramPacket packet) {
|
||||
this.packet = packet;
|
||||
}
|
||||
|
||||
public DatagramPacket getPacket() {
|
||||
return packet;
|
||||
}
|
||||
}
|
29
src/main/java/tech/nevets/sfss/net/packets/SFSInfo.java
Normal file
29
src/main/java/tech/nevets/sfss/net/packets/SFSInfo.java
Normal file
@ -0,0 +1,29 @@
|
||||
package tech.nevets.sfss.net.packets;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class SFSInfo {
|
||||
private final int length;
|
||||
private final String fileName;
|
||||
|
||||
public SFSInfo(int length, String fileName) {
|
||||
if (length < 0) {
|
||||
throw new IllegalArgumentException("Length cannot be negative");
|
||||
}
|
||||
this.length = (byte) length;
|
||||
this.fileName = fileName;
|
||||
}
|
||||
|
||||
public int getLength() {
|
||||
return length;
|
||||
}
|
||||
|
||||
public byte[] toBytes() {
|
||||
byte[] data = new byte[512];
|
||||
System.arraycopy(ByteBuffer.allocate(4).order(ByteOrder.LITTLE_ENDIAN).putInt(length).array(), 0, data, 0, 4);
|
||||
System.arraycopy(fileName.getBytes(StandardCharsets.UTF_8), 0, data, 4, fileName.getBytes(StandardCharsets.UTF_8).length);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user