forked from ethereum/go-ethereum
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ethereum#68 from ethersphere/swarm-pss
swarm, swarm/network, cmd/swarm: pss included in swarm, binary
- Loading branch information
Showing
16 changed files
with
1,629 additions
and
230 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
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
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
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,54 @@ | ||
package ws | ||
|
||
import ( | ||
"net" | ||
|
||
"github.com/ethereum/go-ethereum/logger" | ||
"github.com/ethereum/go-ethereum/logger/glog" | ||
"github.com/ethereum/go-ethereum/rpc" | ||
) | ||
|
||
// Server is the basic configuration needs for the HTTP server and also | ||
// includes CORS settings. | ||
type Server struct { | ||
//Addr string | ||
CorsString string | ||
Endpoint string | ||
} | ||
|
||
// startWS initializes and starts the websocket RPC endpoint. | ||
func StartWSServer(apis []rpc.API, server *Server) error { | ||
|
||
// Generate the whitelist based on the allowed modules | ||
/*whitelist := make(map[string]bool) | ||
for _, module := range modules { | ||
whitelist[module] = true | ||
}*/ | ||
// Register all the APIs exposed by the services | ||
handler := rpc.NewServer() | ||
for _, api := range apis { | ||
//if whitelist[api.Namespace] || (len(whitelist) == 0 && api.Public) { | ||
if err := handler.RegisterName(api.Namespace, api.Service); err != nil { | ||
return err | ||
} | ||
glog.V(logger.Debug).Infof("WebSocket registered %T under '%s'", api.Service, api.Namespace) | ||
//} | ||
} | ||
// All APIs registered, start the HTTP listener | ||
var ( | ||
listener net.Listener | ||
err error | ||
) | ||
if listener, err = net.Listen("tcp", server.Endpoint); err != nil { | ||
return err | ||
} | ||
rpc.NewWSServer(server.CorsString, handler).Serve(listener) | ||
glog.V(logger.Info).Infof("WebSocket endpoint opened: ws://%s", server.Endpoint) | ||
|
||
// All listeners booted successfully | ||
//n.wsEndpoint = endpoint | ||
//n.wsListener = listener | ||
//n.wsHandler = handler | ||
|
||
return nil | ||
} |
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,62 @@ | ||
package ws | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/ethereum/go-ethereum/logger" | ||
"github.com/ethereum/go-ethereum/logger/glog" | ||
"github.com/ethereum/go-ethereum/rpc" | ||
) | ||
|
||
func init() { | ||
glog.SetV(logger.Detail) | ||
glog.SetToStderr(true) | ||
} | ||
|
||
type TestResult struct { | ||
Foo string `json:"foo"` | ||
} | ||
|
||
func TestStartWSServer(t *testing.T) { | ||
ep := "localhost:8099" | ||
server := &Server{ | ||
Endpoint: ep, | ||
CorsString: "*", | ||
} | ||
apis := []rpc.API{ | ||
{ | ||
Namespace: "pss", | ||
Version: "0.1", | ||
Service: makeFakeAPIHandler(), | ||
Public: true, | ||
}, | ||
} | ||
go func() { | ||
err := StartWSServer(apis, server) | ||
t.Logf("wsserver exited: %v", err) | ||
}() | ||
|
||
time.Sleep(time.Second) | ||
|
||
client, err := rpc.DialWebsocket(context.Background(), "ws://" + ep, "ws://localhost") | ||
if err != nil { | ||
t.Fatalf("could not connect: %v", err) | ||
} else { | ||
t.Logf("client: %v", client) | ||
client.Call(&TestResult{}, "pss_test") | ||
} | ||
|
||
} | ||
|
||
func makeFakeAPIHandler() *FakeAPIHandler { | ||
return &FakeAPIHandler{} | ||
} | ||
|
||
type FakeAPIHandler struct { | ||
} | ||
|
||
func (self *FakeAPIHandler) Test() { | ||
glog.V(logger.Detail).Infof("in fakehandler Test()") | ||
} |
Oops, something went wrong.