Commit efe3cd83 authored by pokkst's avatar pokkst

Upload

parent ef971916
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>xyz.duudl3</groupId>
<artifactId>orion-server</artifactId>
<version>1.0.0</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<!-- Create the bundled JAR, it's easier for some people -->
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<minimizeJar>false</minimizeJar>
<filters>
<filter>
<!-- exclude signatures, the bundling process breaks them for some reason -->
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>bundled</shadedClassifierName>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>xyz.duudl3.orion.Main</mainClass>
</transformer>
</transformers>
<outputFile>target/Orion.jar</outputFile>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<izpack.version>5.0.6</izpack.version>
<izpack.staging>${project.build.directory}/staging</izpack.staging>
<installer-output-filename>cate-${project.version}-installer.jar</installer-output-filename>
</properties>
<dependencies>
<dependency>
<groupId>org.fxmisc.easybind</groupId>
<artifactId>easybind</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>de.jensd</groupId>
<artifactId>fontawesomefx</artifactId>
<version>8.0.0</version>
</dependency>
<dependency>
<groupId>net.glxn</groupId>
<artifactId>qrgen</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.7</version>
</dependency>
<dependency>
<groupId>com.lambdaworks</groupId>
<artifactId>scrypt</artifactId>
<version>1.4.0</version>
</dependency>
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>4.2.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<version>1.7.7</version>
</dependency>
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>4.2.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.controlsfx</groupId>
<artifactId>controlsfx</artifactId>
<version>8.40.10</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp</groupId>
<artifactId>okhttp</artifactId>
<version>2.7.2</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>17.0</version>
</dependency>
<dependency>
<groupId>com.madgag.spongycastle</groupId>
<artifactId>core</artifactId>
<version>1.51.0.0</version>
</dependency>
<dependency>
<groupId>com.madgag.spongycastle</groupId>
<artifactId>core</artifactId>
<version>1.51.0.0</version>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>2.5.0</version>
</dependency>
<dependency>
<groupId>org.bitcoinj</groupId>
<artifactId>bitcoinj-core</artifactId>
<version>0.15-SNAPSHOT</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/bitcoinj-core-0.15-SNAPSHOT-bundled.jar</systemPath>
</dependency>
</dependencies>
</project>
This diff is collapsed.
package xyz.duudl3.orion;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Date;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import org.bitcoinj.core.NetworkParameters;
import org.bitcoinj.core.listeners.DownloadProgressTracker;
import org.bitcoinj.kits.WalletAppKit;
import org.bitcoinj.params.MainNetParams;
import org.bitcoinj.params.TestNet3Params;
import org.bitcoinj.utils.Threading;
import org.bitcoinj.wallet.DeterministicSeed;
import xyz.duudl3.orion.network.ConnectionHandler;
public class Main extends Application
{
public static NetworkParameters params = null;
public static final String APP_NAME = "Orion Server";
private static String WALLET_FILE_NAME = "orion_server_wallet";
public static WalletAppKit walletAppKit;
public static Main instance;
private StackPane uiStack;
private Pane mainUI;
public MainController controller;
public Stage mainWindow;
private static ConnectionHandler connHandler;
public static void main(String[] args) throws IOException
{
params = MainNetParams.get();
connHandler = new ConnectionHandler();
connHandler.initialize();
launch(args);
}
@Override
public void start(Stage mainWindow) throws Exception {
try {
loadWindow(mainWindow);
} catch (Throwable e) {
throw e;
}
}
private void loadWindow(Stage mainWindow) throws IOException {
this.mainWindow = mainWindow;
instance = this;
FXMLLoader loader2 = new FXMLLoader();
loader2.setLocation(getClass().getResource("main.fxml"));
AnchorPane pane2 = loader2.<AnchorPane>load();
controller = loader2.getController();
Scene scene2 = new Scene(pane2);
scene2.getStylesheets().add(getClass().getResource("styles.css").toString());
mainWindow.setScene(scene2);
mainWindow.setResizable(false);
mainWindow.setMaxWidth(800);
mainWindow.setMaxHeight(451);
mainWindow.getIcons().add(new Image("https://duudl3.xyz/img/orion_client.png"));
Threading.USER_THREAD = Platform::runLater;
setupWalletKit(null);
if (walletAppKit.isChainFileLocked()) {
System.out.println("ERROR: Chain file locked. Exiting...");
Platform.exit();
return;
}
mainWindow.show();
}
public void setupWalletKit(DeterministicSeed seed) {
// If seed is non-null it means we are restoring from backup.
walletAppKit = new WalletAppKit(params, new File("."), WALLET_FILE_NAME)
{
@Override
protected void onSetupCompleted() {
walletAppKit.wallet().allowSpendingUnconfirmedTransactions();
Platform.runLater(controller::onWalletSetup);
}
};
walletAppKit.setDownloadListener(new DownloadProgressTracker() {
@Override
protected void progress(double pct, int blocksSoFar, Date date) {
super.progress(pct, blocksSoFar, date);
int percentage = (int) pct;
}
@Override
protected void doneDownload() {
super.doneDownload();
//watchingWallet = Wallet.fromWatchingKey(parameters, DeterministicKey.deserializeB58(null, serialized, parameters));
}
});
walletAppKit.setBlockingStartup(false).setUserAgent(APP_NAME, "1.0");
if (seed != null)
walletAppKit.restoreWalletFromSeed(seed);
walletAppKit.startAsync();
}
public static ConnectionHandler getConnectionHandler()
{
return connHandler;
}
@Override
public void stop() throws Exception {
walletAppKit.stopAsync();
walletAppKit.awaitTerminated();
System.exit(0);
}
}
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package xyz.duudl3.orion;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.scene.control.*;
import org.bitcoinj.core.Address;
import org.bitcoinj.core.Coin;
import org.bitcoinj.core.InsufficientMoneyException;
import org.bitcoinj.core.Transaction;
import org.bitcoinj.wallet.SendRequest;
import org.bitcoinj.wallet.Wallet;
import org.spongycastle.util.encoders.Hex;
import xyz.duudl3.orion.tx.BroadcastHelper;
import java.io.UnsupportedEncodingException;
/**
* Gets created auto-magically by FXMLLoader via reflection. The widget fields are set to the GUI controls they're named
* after. This class handles all the updates and event handling for the main UI.
*/
public class MainController {
public Label balance;
public TextField toAddress;
// Called by FXMLLoader.
public void initialize() {
}
public void onWalletSetup() {
String currentBalance = Main.walletAppKit.wallet().getBalance(Wallet.BalanceType.ESTIMATED).toFriendlyString();
balance.setText(currentBalance);
Main.walletAppKit.wallet().addChangeEventListener(Platform::runLater, wallet -> {
String currentBalance1 = Main.walletAppKit.wallet().getBalance(Wallet.BalanceType.ESTIMATED).toFriendlyString();
balance.setText(currentBalance1);
});
}
public void withdraw(ActionEvent actionEvent) {
String modifiedBalance = balance.getText().replace(" BTC", "");
Coin coinAmt = Coin.parseCoin(modifiedBalance);
if(coinAmt.getValue() > 0.0)
{
Address destination = Address.fromString(Main.params, toAddress.getText());
SendRequest req = null;
req = SendRequest.emptyWallet(destination);
req.ensureMinRequiredFee = false;
//converting because the UI uses sats/byte, so we need to convert that to fee per kb here
req.feePerKb = Coin.valueOf(5L * 1000L);
Transaction tx = null;
try {
tx = Main.walletAppKit.wallet().sendCoinsOffline(req);
} catch (InsufficientMoneyException e) {
e.printStackTrace();
}
byte[] txHexBytes = Hex.encode(tx.bitcoinSerialize());
String txHex = null;
try {
txHex = new String(txHexBytes, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
System.out.println("Created raw transaction: " + txHex);
System.out.println("Broadcasting raw transaction...");
BroadcastHelper helper = new BroadcastHelper(false, false);
helper.broadcast(txHex);
}
}
}
package xyz.duudl3.orion.client;
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;
import java.net.UnknownHostException;
import java.security.MessageDigest;
import javax.xml.bind.DatatypeConverter;
public class ClientConnection {
private Socket clientSocket;
public ClientConnection(String server, int port) throws UnknownHostException, IOException
{
(new Thread() {
@Override
public void run() {
try {
System.out.println("[HOME] Initiating our client. Connecting to " + server + ":" + port);
/**clientSocket = new Socket(server, port);
sendFile("./testfolder/pic2.jpg");
clientSocket = new Socket(server, port);
sendFile("./testfolder/pic.jpg");
clientSocket = new Socket(server, port);
sendFile("./testfolder/pic3.jpg");
clientSocket = new Socket(server, port);
sendFile("./testfolder/test4.txt");
clientSocket = new Socket(server, port);
sendFile("./testfolder/test3.txt");
clientSocket = new Socket(server, port);
sendFile("./testfolder/test2.txt");
clientSocket = new Socket(server, port);
sendFile("./testfolder/test.txt");
clientSocket = new Socket(server, port);
sendFile("./testfolder/me.txt");**/
//clientSocket = new Socket(server, port);
//getFile("37de10b044dd3396c4f8b15496da6db072aba7d889d5f5152544bd8687eeeadb.jpg");
clientSocket = new Socket(server, port);
requestFileList();
Thread.sleep(200);
} catch (UnknownHostException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void sendFile(String file) throws IOException {
DataOutputStream dos1 = new DataOutputStream(getClientConnection().getOutputStream());
/**
* Notify the nodes we're sending data to of the file type we're about to send.
*/
dos1.writeInt(0);
dos1.writeUTF(getFileExtension(new File(file)));
/**
* Begin sending the data to the nodes.
*/
FileInputStream fis = new FileInputStream(file);
File fileSending = new File(file);
dos1.writeInt((int)fileSending.length());
byte[] buffer = new byte[(int) fileSending.length()];
while (fis.read(buffer) > 0) {
dos1.write(buffer);
}
fis.close();
dos1.close();
}
public void getFile(String fileHash) throws IOException
{
DataOutputStream dos1 = new DataOutputStream(getClientConnection().getOutputStream());
/**
* Notify the nodes what file we want by giving them the file hash.
*/
dos1.writeInt(1);
dos1.writeUTF(fileHash);
/**
* Here we receive a response from the server with the file data.
*/
DataInputStream dis1 = new DataInputStream(getClientConnection().getInputStream());
//Getting file extension
String fileExtension = dis1.readUTF();
int fileSize = dis1.readInt();
System.out.println("DOWNLOADED FILE EXT. " + fileExtension);
long time = System.currentTimeMillis();
boolean tmpFolder = new File("./client_tmp/").mkdir();
String fileName = "./client_tmp/" + getStringHash("" + time) + fileExtension;
/**
* Prepare to read the file the server is sending.
*/
FileOutputStream fos = new FileOutputStream(fileName);
byte[] buffer = new byte[fileSize];
/**
* Read the data.
*/
int read = 0;
while ((read = dis1.read(buffer)) != -1) {
fos.write(buffer, 0, read);
}
//Close the file
fos.close();
//Print the hash of the data that was sent from the client.
System.out.println("Downloaded file hash: " + getFileHash(new File(fileName)).toLowerCase());
/**
* Rename the file to the hash of the actual data and not our temporary fileName above. This is so other clients can retrieve
* the file if they have the file hash.
*/
File newFile = new File(fileName);
boolean dataFolder = new File("./client_downloads/").mkdir();
String newFileName = "./client_downloads/" + getFileHash(new File(fileName)).toLowerCase();
File permFile = new File(newFileName + fileExtension);
if(!permFile.exists()){
boolean renamed = newFile.renameTo(permFile);
}
else{
newFile.delete();
}
dis1.close();
dos1.close();
}
public void requestFileList() throws IOException
{
DataOutputStream dos1 = new DataOutputStream(getClientConnection().getOutputStream());
/**
* Notify the nodes what file we want by giving them the file hash.
*/
dos1.writeInt(2);
/**
* Here we receive a response from the server with the file data.
*/
BufferedInputStream bis1 = new BufferedInputStream(getClientConnection().getInputStream());
DataInputStream dis1 = new DataInputStream(bis1);
int fileCount = dis1.readInt();
for (int i = 0; i < fileCount; i++)
{
long fileSize = dis1.readLong();
String fileName = dis1.readUTF();
System.out.println("File: " + fileName + " Size: " + fileSize);
}
dis1.close();
bis1.close();
dos1.close();
}
public String getFileHash(File input) {
try (InputStream in = new FileInputStream(input)) {
MessageDigest digest = MessageDigest.getInstance("SHA-256");
byte[] block = new byte[(int)input.length()];
int length;
while ((length = in.read(block)) > 0) {
digest.update(block, 0, length);
}
return DatatypeConverter.printHexBinary(digest.digest());
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public String getStringHash(String value)
{
try{
MessageDigest md = MessageDigest.getInstance("SHA-256");
md.update(value.getBytes());
return bytesToHex(md.digest());
} catch(Exception ex){
throw new RuntimeException(ex);
}
}
private String bytesToHex(byte[] bytes)
{
StringBuffer result = new StringBuffer();
for (byte b : bytes) result.append(Integer.toString((b & 0xff) + 0x100, 16).substring(1));
return result.toString();
}
private String getFileExtension(File file) {
String name = file.getName();
int lastIndexOf = name.lastIndexOf(".");
if (lastIndexOf == -1) {
return ""; // empty extension
}
return name.substring(lastIndexOf);
}
}).start();
}
public Socket getClientConnection()
{
return clientSocket;
}
}
package xyz.duudl3.orion.network;
import java.io.IOException;
import xyz.duudl3.orion.client.ClientConnection;
import xyz.duudl3.orion.server.ServerConnection;
public class ConnectionHandler {
private ServerConnection serverConn;
private ClientConnection clientConn;
public ConnectionHandler()
{
}
public void initialize() throws IOException
{
serverConn = new ServerConnection(NetworkConstants.PORT);
//clientConn = new ClientConnection("73.136.173.136", NetworkConstants.PORT);
}
public ServerConnection getServer()
{
return serverConn;
}
public ClientConnection getClient()
{
return clientConn;
}
}
package xyz.duudl3.orion.network;
public class NetworkConstants {
public static final int PORT = 7655;
}
\ No newline at end of file
package xyz.duudl3.orion.server;
import xyz.duudl3.orion.Main;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;