Skip to content

Commit

Permalink
Merge branch 'gui'
Browse files Browse the repository at this point in the history
  • Loading branch information
Stratehm committed Jul 3, 2014
2 parents 9a9b125 + c03b718 commit 185a976
Show file tree
Hide file tree
Showing 33 changed files with 10,197 additions and 26 deletions.
5 changes: 5 additions & 0 deletions assembly.xml → assemblies/distAssembly.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<includeBaseDirectory>true</includeBaseDirectory>
<dependencySets>
<dependencySet>
<useProjectArtifact>false</useProjectArtifact>
<outputDirectory>/lib</outputDirectory>
</dependencySet>
</dependencySets>
Expand All @@ -32,5 +33,9 @@
<source>src/main/resources/stratum-proxy-minimal-sample.conf</source>
<outputDirectory>/</outputDirectory>
</file>
<file>
<source>${project.build.directory}/stratum-proxy-webapp.jar</source>
<outputDirectory>/lib</outputDirectory>
</file>
</files>
</assembly>
13 changes: 13 additions & 0 deletions assemblies/webappAssembly.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<assembly>
<id>webapp</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>src/main/resources/webapp</directory>
<outputDirectory>/</outputDirectory>
</fileSet>
</fileSets>
</assembly>
51 changes: 42 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@
<version>1.2.17</version>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
<version>1.7.7</version>
</dependency>

<!-- Utils -->
<dependency>
<groupId>com.google.guava</groupId>
Expand All @@ -97,6 +103,16 @@
</dependencies>

<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>webapp/*</exclude>
<exclude>**/headerGPLv3Template.txt</exclude>
<exclude>**/*.conf</exclude>
</excludes>
</resource>
</resources>
<pluginManagement>
<plugins>
<plugin>
Expand Down Expand Up @@ -142,6 +158,9 @@
<mainClass>strat.mining.stratum.proxy.Launcher</mainClass>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
<manifestEntries>
<Class-Path>lib/stratum-proxy-webapp.jar</Class-Path>
</manifestEntries>
</archive>
</configuration>
</plugin>
Expand All @@ -153,26 +172,40 @@
<includes>
<include>**/*.java</include>
</includes>
<header>headerGPLv3Template.txt</header>
<header>src/main/resources/headerGPLv3Template.txt</header>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<descriptors>
<descriptor>assembly.xml</descriptor>
</descriptors>
<finalName>stratum-proxy-${project.version}</finalName>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
<executions>
<execution>
<id>zip-package</id>
<id>webapp-package</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>assemblies/webappAssembly.xml</descriptor>
</descriptors>
<finalName>stratum-proxy</finalName>
<appendAssemblyId>true</appendAssemblyId>
</configuration>
</execution>
<execution>
<id>dist-zip-package</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>assemblies/distAssembly.xml</descriptor>
</descriptors>
<finalName>stratum-proxy-${project.version}</finalName>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
</execution>
</executions>
</plugin>
Expand Down
108 changes: 103 additions & 5 deletions src/main/java/strat/mining/stratum/proxy/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,24 @@
*/
package strat.mining.stratum.proxy;

import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.List;

import javax.ws.rs.core.UriBuilder;

import org.glassfish.grizzly.http.CompressionConfig.CompressionMode;
import org.glassfish.grizzly.http.server.CLStaticHttpHandler;
import org.glassfish.grizzly.http.server.HttpHandler;
import org.glassfish.grizzly.http.server.HttpServer;
import org.glassfish.grizzly.http.server.Request;
import org.glassfish.grizzly.http.server.Response;
import org.glassfish.grizzly.http.server.ServerConfiguration;
import org.glassfish.grizzly.http.server.StaticHttpHandler;
import org.glassfish.grizzly.http.server.StaticHttpHandlerBase;
import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
import org.glassfish.jersey.jackson.JacksonFeature;
import org.glassfish.jersey.server.ResourceConfig;
Expand Down Expand Up @@ -72,7 +82,7 @@ public static void main(String[] args) {
initGetwork(configurationManager);

// Initialize the rest services
initRestServices(configurationManager);
initHttpServices(configurationManager);

// Initialize the hashrate recorder
initHashrateRecorder();
Expand All @@ -97,6 +107,9 @@ private static void initShutdownHook() {
Thread hookThread = new Thread() {
public void run() {

// Shutdown the database
DatabaseManager.close();

// Start a timer task that will exit the program after 1 second
// if the cleanup is not over.
Timer.getInstance().schedule(new Timer.Task() {
Expand Down Expand Up @@ -154,16 +167,101 @@ private static void initDatabaseManager() {
}

/**
* Initialize the REST services.
* Initialize the HTTP services.
*
* @param configurationManager
* @throws IOException
*/
private static void initRestServices(ConfigurationManager configurationManager) {
private static void initHttpServices(ConfigurationManager configurationManager) throws IOException {
URI baseUri = UriBuilder.fromUri("http://" + configurationManager.getRestBindAddress()).port(configurationManager.getRestListenPort())
.build();
.path("/proxy").build();
ResourceConfig config = new ResourceConfig(ProxyResources.class);
config.register(JacksonFeature.class);
apiHttpServer = GrizzlyHttpServerFactory.createHttpServer(baseUri, config);
apiHttpServer = GrizzlyHttpServerFactory.createHttpServer(baseUri, config, false);
ServerConfiguration serverConfiguration = apiHttpServer.getServerConfiguration();
apiHttpServer.getListener("grizzly").getCompressionConfig().setCompressionMode(CompressionMode.ON);
apiHttpServer.getListener("grizzly").getCompressionConfig()
.setCompressableMimeTypes("text/javascript", "application/json", "text/html", "text/css");
apiHttpServer.getListener("grizzly").getCompressionConfig().setCompressionMinSize(1024);
HttpHandler staticHandler = getStaticHandler();
if (staticHandler != null) {
serverConfiguration.addHttpHandler(staticHandler, "/");
}

apiHttpServer.start();
}

/**
* Return the handler to serve static content.
*
* @return
*/
private static HttpHandler getStaticHandler() {
StaticHttpHandlerBase handler = null;
// If the application is running form the jar file, use a Class Loader
// to get the web content.
if (ConfigurationManager.isRunningFromJar()) {
try {
File stratumProxyWebappJarFile = new File(ConfigurationManager.getInstallDirectory(), "lib/stratum-proxy-webapp.jar");
if (stratumProxyWebappJarFile.exists()) {
handler = new CLStaticHttpHandler(new URLClassLoader(
new URL[] { new URL("file://" + stratumProxyWebappJarFile.getAbsolutePath()) }), "/") {

private final Logger SUB_LOGGER = LoggerFactory.getLogger(CLStaticHttpHandler.class);

protected boolean handle(String resourcePath, Request request, Response response) throws Exception {
SUB_LOGGER.trace("Requested resource: {}.", resourcePath);
long time = System.currentTimeMillis();
String resourcePathFiltered = resourcePath;
// If the root is requested, then replace the
// requested resource by index.html
if ("/".equals(resourcePath)) {
resourcePathFiltered = "/index.html";
}
boolean found = super.handle(resourcePathFiltered, request, response);
time = System.currentTimeMillis() - time;
if (found) {
SUB_LOGGER.trace("Resource sent in {} ms: {}.", time, resourcePath);
} else {
SUB_LOGGER.trace("Resource not found: {}.", resourcePath);
}
return found;
}

};
} else {
LOGGER.warn("lib/stratum-proxy-webapp.jar not found. GUI will not be available.");
}
} catch (Exception e) {
LOGGER.warn("Failed to initialize the Web content loader. GUI will not be available.", e);
}
} else {
// If not running from a jar, it is running from the dev
// environment. So use a static handler.
File installPath = new File(ConfigurationManager.getInstallDirectory());
File docRootPath = new File(installPath.getParentFile(), "src/main/resources/webapp");
handler = new StaticHttpHandler(docRootPath.getAbsolutePath()) {
private final Logger SUB_LOGGER = LoggerFactory.getLogger(StaticHttpHandler.class);

protected boolean handle(String uri, Request request, Response response) throws Exception {
SUB_LOGGER.trace("Requested resource: {}.", uri);
long time = System.currentTimeMillis();
boolean found = super.handle(uri, request, response);
time = System.currentTimeMillis() - time;
if (found) {
SUB_LOGGER.trace("Resource sent in {} ms: {}.", time, uri);
} else {
SUB_LOGGER.trace("Resource not found: {}.", uri);
}
return found;
}

};
}
// Disable the file cache if in development.
handler.setFileCacheEnabled(!ConfigurationManager.getVersion().equals("Dev"));

return handler;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,12 @@ public class CommandLineOptions {
@Option(name = "--log-directory", usage = "The directory where logs will be written", handler = FileOptionHandler.class, metaVar = "directory")
private File logDirectory;

@Option(name = "--log-level", usage = "The level of log: OFF, FATAL, ERROR, WARN, INFO, DEBUG, TRACE. Default is INFO", handler = LogLevelOptionHandler.class, metaVar = "LEVEL")
@Option(name = "--log-level", usage = "The level of log: OFF, FATAL, ERROR, WARN, INFO, DEBUG, TRACE. Default is INFO. DEBUG and TRACE levels may augment rejected shares.", handler = LogLevelOptionHandler.class, metaVar = "LEVEL")
private Level logLevel;

@Option(name = "--api-log-level", usage = "Enable the API logging with the given level. Valid levels are OFF, FATAL, ERROR, WARN, INFO, DEBUG, TRACE. May degrade performances.", handler = LogLevelOptionHandler.class, metaVar = "LEVEL")
private Level apiLogLevel;

@Option(name = "--stratum-listen-port", usage = "The port number to listen incoming connections. (3333 by default)", metaVar = "portNumber")
private Integer stratumListeningPort;

Expand Down Expand Up @@ -278,6 +281,10 @@ public Boolean isNoMidstate() {
return noMidstate;
}

public Level getApiLogLevel() {
return apiLogLevel;
}

public Boolean isValidateSha26GetworkShares() {
return validateSha26GetworkShares;
}
Expand Down
Loading

0 comments on commit 185a976

Please sign in to comment.