mirror of
https://github.com/tendermint/tendermint.git
synced 2026-02-07 12:30:45 +00:00
support unix domain websockets
This commit is contained in:
@@ -16,24 +16,18 @@ import (
|
||||
|
||||
// Set the net.Dial manually so we can do http over tcp or unix.
|
||||
// Get/Post require a dummyDomain but it's over written by the Transport
|
||||
var dummyDomain = "http://dummyDomain/"
|
||||
var dummyDomain = "http://dummyDomain"
|
||||
|
||||
func dialFunc(sockType, remote string) func(string, string) (net.Conn, error) {
|
||||
func dialer(remote string) func(string, string) (net.Conn, error) {
|
||||
return func(proto, addr string) (conn net.Conn, err error) {
|
||||
return net.Dial(sockType, remote)
|
||||
return net.Dial(rpctypes.SocketType(remote), remote)
|
||||
}
|
||||
}
|
||||
|
||||
// remote is IP:PORT or /path/to/socket
|
||||
func socketTransport(remote string) *http.Transport {
|
||||
if rpctypes.SocketType(remote) == "unix" {
|
||||
return &http.Transport{
|
||||
Dial: dialFunc("unix", remote),
|
||||
}
|
||||
} else {
|
||||
return &http.Transport{
|
||||
Dial: dialFunc("tcp", remote),
|
||||
}
|
||||
return &http.Transport{
|
||||
Dial: dialer(remote),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,7 +99,7 @@ func (c *ClientURI) call(method string, params map[string]interface{}, result in
|
||||
return nil, err
|
||||
}
|
||||
log.Info(Fmt("URI request to %v (%v): %v", c.remote, method, values))
|
||||
resp, err := c.client.PostForm(dummyDomain+method, values)
|
||||
resp, err := c.client.PostForm(dummyDomain+"/"+method, values)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -19,16 +19,18 @@ const (
|
||||
|
||||
type WSClient struct {
|
||||
QuitService
|
||||
Address string
|
||||
Address string // IP:PORT or /path/to/socket
|
||||
Endpoint string // /websocket/url/endpoint
|
||||
*websocket.Conn
|
||||
ResultsCh chan json.RawMessage // closes upon WSClient.Stop()
|
||||
ErrorsCh chan error // closes upon WSClient.Stop()
|
||||
}
|
||||
|
||||
// create a new connection
|
||||
func NewWSClient(addr string) *WSClient {
|
||||
func NewWSClient(addr, endpoint string) *WSClient {
|
||||
wsClient := &WSClient{
|
||||
Address: addr,
|
||||
Endpoint: endpoint,
|
||||
Conn: nil,
|
||||
ResultsCh: make(chan json.RawMessage, wsResultsChannelCapacity),
|
||||
ErrorsCh: make(chan error, wsErrorsChannelCapacity),
|
||||
@@ -38,7 +40,7 @@ func NewWSClient(addr string) *WSClient {
|
||||
}
|
||||
|
||||
func (wsc *WSClient) String() string {
|
||||
return wsc.Address
|
||||
return wsc.Address + ", " + wsc.Endpoint
|
||||
}
|
||||
|
||||
func (wsc *WSClient) OnStart() error {
|
||||
@@ -52,10 +54,14 @@ func (wsc *WSClient) OnStart() error {
|
||||
}
|
||||
|
||||
func (wsc *WSClient) dial() error {
|
||||
|
||||
// Dial
|
||||
dialer := websocket.DefaultDialer
|
||||
dialer := &websocket.Dialer{
|
||||
NetDial: dialer(wsc.Address),
|
||||
Proxy: http.ProxyFromEnvironment,
|
||||
}
|
||||
rHeader := http.Header{}
|
||||
con, _, err := dialer.Dial(wsc.Address, rHeader)
|
||||
con, _, err := dialer.Dial("ws://"+dummyDomain+wsc.Endpoint, rHeader)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user