Skip to content

Commit

Permalink
package refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Karasiq committed Sep 14, 2015
1 parent b45f870 commit d1457ee
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 34 deletions.
11 changes: 8 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name := "proxychain"

organization := "com.karasiq"

version := "1.3"
version := "1.4"

scalaVersion := "2.11.7"

Expand All @@ -12,7 +12,6 @@ libraryDependencies ++= Seq(
"commons-io" % "commons-io" % "2.4",
"org.apache.httpcomponents" % "httpclient" % "4.3.3",
"com.typesafe.akka" %% "akka-actor" % "2.3.11",
"com.typesafe.akka" %% "akka-kernel" % "2.3.11",
"com.karasiq" %% "cryptoutils" % "1.0",
"com.karasiq" %% "proxyutils" % "1.0",
"org.scalatest" %% "scalatest" % "2.2.4" % "test",
Expand All @@ -23,4 +22,10 @@ scalacOptions ++= Seq("-optimize", "-deprecation", "-feature")

mainClass in Compile := Some("com.karasiq.proxychain.app.Boot")

enablePlugins(AkkaAppPackaging)
enablePlugins(JavaServerAppPackaging, LinuxPlugin)

maintainer := "Karasiq <[email protected]>"

packageSummary := "Proxychain"

packageDescription := "Proxy-chaining SOCKS/HTTP/TLS proxy server"
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version = 0.13.8
sbt.version = 0.13.9
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
logLevel := Level.Warn

addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.0.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.0.5-M3")
2 changes: 1 addition & 1 deletion setup/setup.iss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#define OutputName "proxychain"
#define MyAppName "Proxychain"
#define MyAppVersion "1.3"
#define MyAppVersion "1.4"
#define MyAppPublisher "Karasiq, Inc."
#define MyAppURL "http://www.github.com/Karasiq"
#define MyAppExeName "bin\proxychain.bat"
Expand Down
53 changes: 27 additions & 26 deletions src/main/scala/com/karasiq/proxychain/app/Boot.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,46 @@ import akka.actor.{ActorSystem, Props}
import akka.event.Logging
import akka.io.Tcp.Bind
import akka.io.{IO, Tcp}
import akka.kernel.Bootable
import com.karasiq.fileutils.PathUtils._
import com.karasiq.proxychain.AppConfig
import com.karasiq.proxychain.script.ScriptEngine
import com.typesafe.config.Config

final class Boot extends Bootable {
object Boot extends App {
val configFile: Config = AppConfig.externalConfig()
val actorSystem: ActorSystem = ActorSystem("ProxyChain", configFile.resolve())

override def startup(): Unit = {
val cfg = configFile.getConfig("proxyChain")
val host = cfg.getString("host")
val cfg = configFile.getConfig("proxyChain")
val host = cfg.getString("host")

val config: AppConfig = asPath(cfg.getString("script")) match {
case script if script.isRegularFile
actorSystem.log.debug("Loading script: {}", script)
val scriptEngine = new ScriptEngine(Logging.getLogger(actorSystem, "ScriptEngine"))
scriptEngine.asConfig(script)
val config: AppConfig = asPath(cfg.getString("script")) match {
case script if script.isRegularFile
actorSystem.log.debug("Loading script: {}", script)
val scriptEngine = new ScriptEngine(Logging.getLogger(actorSystem, "ScriptEngine"))
scriptEngine.asConfig(script)

case _
AppConfig(cfg) // Default
}

// Start server
case _
AppConfig(cfg) // Default
}

val port = cfg.getInt("port")
if (port != 0) {
val server = actorSystem.actorOf(Props(classOf[Server], config))
IO(Tcp)(actorSystem).tell(Bind(server, new InetSocketAddress(host, port)), server)
}
// Start server

val tlsPort = cfg.getInt("tls-port")
if (tlsPort != 0) {
val server = actorSystem.actorOf(Props(classOf[TLSServer], new InetSocketAddress(host, tlsPort), config))
}
val port = cfg.getInt("port")
if (port != 0) {
val server = actorSystem.actorOf(Props(classOf[Server], config))
IO(Tcp)(actorSystem).tell(Bind(server, new InetSocketAddress(host, port)), server)
}

override def shutdown(): Unit = {
actorSystem.shutdown()
val tlsPort = cfg.getInt("tls-port")
if (tlsPort != 0) {
val server = actorSystem.actorOf(Props(classOf[TLSServer], new InetSocketAddress(host, tlsPort), config))
}

Runtime.getRuntime.addShutdownHook(new Thread(new Runnable {
override def run(): Unit = {
actorSystem.log.debug("Shutting down ActorSystem")
actorSystem.shutdown()
actorSystem.awaitTermination()
}
}))
}
7 changes: 5 additions & 2 deletions src/main/scala/com/karasiq/proxychain/app/Server.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.karasiq.proxychain.app

import java.io.IOException
import java.net.InetSocketAddress
import java.nio.channels.{ServerSocketChannel, SocketChannel}
import java.util.concurrent.Executors
Expand Down Expand Up @@ -49,8 +50,10 @@ class TLSServer(address: InetSocketAddress, cfg: AppConfig) extends Actor with A
serverSocket.bind(address)
acceptor.execute(new Runnable {
override def run(): Unit = {
while (serverSocket.isOpen) {
self ! Accepted(serverSocket.accept())
control.Exception.ignoring(classOf[IOException]) {
while (serverSocket.isOpen) {
self ! Accepted(serverSocket.accept())
}
}
}
})
Expand Down

0 comments on commit d1457ee

Please sign in to comment.