Skip to content

Commit

Permalink
main.go : * Added a sync.Mutex to the conf struct so as to prevent any
Browse files Browse the repository at this point in the history
	    unsafe access in getProxyStruct by locking when updating the
	    conf in the Reloader go routine.
          * Added support for a custom control socket file location
	  * Updated Readme
  • Loading branch information
aki237 committed Apr 29, 2017
1 parent a3eff57 commit 4633229
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
11 changes: 6 additions & 5 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ following ...
],
"domaincachefile" : "<cacheFileLocation>",
"verbose":true,
"contorlsocket":"/tmp/proGY-control",
"loggerport" : <SomePortAsInteger>
}
```
Expand All @@ -72,6 +73,7 @@ following ...
}
],
"domaincachefile" : "/Users/stinson/.cache/dnscache.pgy",
"contorlsocket":"/tmp/proGY-control",
"verbose":true,
"loggerport" : 3030
}
Expand Down Expand Up @@ -110,10 +112,10 @@ external binary dependancy, replicating the functionalities of `ss` and `ps` com
write those packages will be apperitiated.

### Control Port
A new feature for controlling proGY has been added. A unix socket running at `/tmp/proGY-control` will be running for controlling the
daemon. Syntax for controlling it will be like a simple QBasic statement. Right now only one command has been added.
To reload the configuration on the fly without stopping use the [`socat`](http://www.dest-unreach.org/socat/) tool to connect to the
domain socket and communicate with it.
A new feature for controlling proGY has been added. A unix socket running at any location (Default Location if not specified : `/tmp/proGY-control`)
specified in the config file will be running for controlling the daemon. Syntax for controlling it will be like a simple
QBasic statement. Right now only one command has been added. To reload the configuration on the fly without stopping use
the [`socat`](http://www.dest-unreach.org/socat/) tool to connect to the domain socket and communicate with it.
```shell
$ socat - UNIX:/tmp/proGY-control
RELOAD /etc/progy.json
Expand All @@ -123,5 +125,4 @@ RELOAD /etc/progy.json
**Usage** : `RELOAD [filename]` - any file with the proGY's configuration structure as specified above will be good.

## Future Plans
+ Ability to write plugins for proGY using plugin language like Lisp
+ Enable transparent proxying for TLS connections also.
6 changes: 4 additions & 2 deletions control.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import (
"strings"
)

func listenUnixControl(fileChannel chan string) {
socketName := "/tmp/proGY-control"
func listenUnixControl(socketName string, fileChannel chan string) {
if socketName == "" {
socketName = "/tmp/proGY-control"
}
if _, err := os.Stat(socketName); err == nil {
if os.Remove(socketName) != nil {
fmt.Println(err)
Expand Down
8 changes: 7 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"os"
"os/exec"
"strings"
"sync"

"github.com/aki237/proGY/logger"
)
Expand All @@ -35,15 +36,19 @@ type Config struct {
Verbose bool // Verbose : Whether to be verbose about the output
Domaincachefile string // Size of the DNS Cache to be saved during runtime
Loggerport int // What port to run the Logger at
ControlSocket string // At which file to run the unix socket for controlling proGY
*sync.Mutex
}

func (c *Config) Reloader(fileChannel chan string) {
for {
filename := <-fileChannel
c.Lock()
temp := parseConfig(filename)
c.Creds = temp.Creds
c.Verbose = temp.Verbose
c.Domaincachefile = temp.Domaincachefile
c.Unlock()
}
}

Expand Down Expand Up @@ -114,6 +119,7 @@ func main() {
wordPtr := flag.String("config", home+"/.progy", "Configuration file to be provided for proGY")
flag.Parse()
conf := parseConfig(*wordPtr)
conf.Mutex = &sync.Mutex{}
laddr, err := net.ResolveTCPAddr("tcp", conf.Listenaddress)
check(err)
listener, err := net.ListenTCP("tcp", laddr)
Expand All @@ -123,7 +129,7 @@ func main() {
err = logger.Init(conf.Loggerport)
check(err)
fileChannel := make(chan string)
go listenUnixControl(fileChannel)
go listenUnixControl(conf.ControlSocket, fileChannel)
go conf.Reloader(fileChannel)
for {
conn, err := listener.AcceptTCP()
Expand Down

0 comments on commit 4633229

Please sign in to comment.