-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Charles-Antoine Mathieu
committed
Feb 21, 2018
1 parent
12f9059
commit b161950
Showing
18 changed files
with
834 additions
and
549 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
for i in $(ps faux | grep wsp_ | grep -v grep | awk '{ print $2 }') ; do kill -9 $i ; done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,66 @@ | ||
package client | ||
|
||
import ( | ||
"crypto/tls" | ||
"net/http" | ||
|
||
"github.com/gorilla/websocket" | ||
"github.com/root-gg/wsp/common" | ||
"log" | ||
) | ||
|
||
// Client connects to one or more Server using HTTP websockets | ||
// Client connects to one or more Server using HTTP WebSocket | ||
// The Server can then send HTTP requests to execute | ||
type Client struct { | ||
Config *Config | ||
Config *Config | ||
validator *common.RequestValidator | ||
|
||
client *http.Client | ||
dialer *websocket.Dialer | ||
pools map[string]*Pool | ||
httpClient *http.Client | ||
dialer *websocket.Dialer | ||
pools map[string]*Pool | ||
} | ||
|
||
// NewClient creates a new Proxy | ||
func NewClient(config *Config) (c *Client) { | ||
c = new(Client) | ||
c.Config = config | ||
c.client = &http.Client{} | ||
c.dialer = &websocket.Dialer{} | ||
c.pools = make(map[string]*Pool) | ||
func NewClient(config *Config) (client *Client) { | ||
client = new(Client) | ||
client.Config = config | ||
|
||
client.validator = &common.RequestValidator{ | ||
Whitelist: config.Whitelist, | ||
Blacklist: config.Blacklist, | ||
} | ||
err := client.validator.Initialize() | ||
if err != nil { | ||
log.Fatalf("Unable to initialize the request validator : %s", err) | ||
} | ||
|
||
// WebSocket tcp dialer to connect to the remote WSP servers | ||
client.dialer = &websocket.Dialer{} | ||
|
||
// HTTP client to execute HTTP requests received by the WebSocket tunnels | ||
tr := &http.Transport{ | ||
TLSClientConfig: &tls.Config{InsecureSkipVerify: client.Config.InsecureSkipVerify}, | ||
} | ||
client.httpClient = &http.Client{Transport: tr} | ||
|
||
client.pools = make(map[string]*Pool) | ||
|
||
return | ||
} | ||
|
||
// Start the Proxy | ||
func (c *Client) Start() { | ||
for _, target := range c.Config.Targets { | ||
pool := NewPool(c, target, c.Config.SecretKey) | ||
c.pools[target] = pool | ||
go pool.Start() | ||
func (client *Client) Start() { | ||
for _, target := range client.Config.Targets { | ||
pool := NewPool(client, target) | ||
client.pools[target] = pool | ||
pool.start() | ||
} | ||
} | ||
|
||
// Shutdown the Proxy | ||
func (c *Client) Shutdown() { | ||
for _, pool := range c.pools { | ||
pool.Shutdown() | ||
func (client *Client) Shutdown() { | ||
for _, pool := range client.pools { | ||
pool.close() | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.