Skip to content

Commit 79acd36

Browse files
committed
Add browser handler
1 parent 3ddfab5 commit 79acd36

File tree

9 files changed

+27
-7
lines changed

9 files changed

+27
-7
lines changed

‎mlp-ea-decentralized/common/ga/cluster_test.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//+build !js
2+
13
package ga
24

35
import (

‎mlp-ea-decentralized/common/ga/individualBroadcast.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//+build !js
2+
13
package ga
24

35
import "github.com/hashicorp/memberlist"

‎mlp-ea-decentralized/common/ga/metrics.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//+build !js
2+
13
package ga
24

35
import (

‎mlp-ea-decentralized/common/ga/nodeDelegate.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//+build !js
2+
13
package ga
24

35
import (

‎mlp-ea-decentralized/common/ga/poolModel.go‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"math"
99
"math/rand"
1010
"net"
11+
"net/http"
1112
"reflect"
1213
"runtime"
1314
"sync"
@@ -58,6 +59,8 @@ type PoolModel struct {
5859
popSemaphore semaphore
5960

6061
// Clients communications
62+
WebPort int
63+
WebPath string
6164
evaluations int
6265
wg sync.WaitGroup
6366
stop chan bool
@@ -315,6 +318,7 @@ func (pool *PoolModel) handleEvaluate() {
315318

316319
var (
317320
listenAddr = "0.0.0.0"
321+
webPort = pool.WebPort
318322
nativePort = pool.grpcPort
319323
wasmPort = nativePort + 1
320324
)
@@ -341,6 +345,10 @@ func (pool *PoolModel) handleEvaluate() {
341345
}
342346
defer lisNative.Close()
343347

348+
// Setup HTTP listener to serve webs
349+
Log.Infof("Web Server for bowser collaborators at http://%s:%d/", listenAddr, wasmPort)
350+
go http.ListenAndServe(fmt.Sprintf("%s:%d", listenAddr, webPort), http.FileServer(http.Dir(pool.WebPath)))
351+
344352
// Setup listener for wasm clients based on websockets
345353
lisWasm, err := ws.Listen(fmt.Sprintf("ws://%s:%d", listenAddr, wasmPort), nil)
346354
if err != nil {

‎mlp-ea-decentralized/native/client/client.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
)
1111

1212
var (
13-
serverAddr = flag.String("server", "127.0.0.1:3117", "Server address in format addr:port.")
13+
serverAddr = flag.String("server", "127.0.0.1:2019", "Server address in format addr:port.")
1414
)
1515

1616
func main() {

‎mlp-ea-decentralized/native/server/server.go‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,20 @@ import (
2121
var (
2222
// Opened ports
2323
metricsPort = flag.Int("metricsPort", 2222, "Port for prometheus metrics")
24-
grpcPort = flag.Int("grpcPort", 3117, "Port to listen for grpc requests")
24+
grpcPort = flag.Int("grpcPort", 2019, "Port to listen for grpc requests")
2525
clusterPort = flag.Int("clusterPort", 9999, "Listening port for gossip protocol")
26-
clusterBoostrap = flag.String("clusterBoostrap", "", "comma separated list of peers already ina cluster to join")
26+
clusterBoostrap = flag.String("clusterBootstrap", "", "comma separated list of peers already in a cluster to join")
27+
dataset = flag.String("datasetPath", "../../../datasets/glass.csv", "Dataset to train MLP with")
28+
webPath = flag.String("webPath", "../../web/src/", "Webpage source code that will be served to browser-based collaborators")
29+
webPort = flag.Int("webPort", 8080, "Port to serve webpage to broser based collaborators")
2730
)
2831

2932
func main() {
3033
flag.Parse()
3134

32-
filename := "../../../datasets/glass.csv"
33-
fileContent, err := ioutil.ReadFile(filename)
35+
fileContent, err := ioutil.ReadFile(*dataset)
3436
if err != nil {
35-
logrus.Fatalf("Cannot open %s. Error: %s", filename, err.Error())
37+
logrus.Fatalf("Cannot open %s. Error: %s", *dataset, err.Error())
3638
}
3739

3840
// Patterns initialization
@@ -67,6 +69,8 @@ func main() {
6769
mlp.NewRandMLP)
6870

6971
// Configure extra pool settings
72+
pool.WebPort = *webPort
73+
pool.WebPath = *webPath
7074
pool.Delegate = mlp.DelegateImpl{}
7175
pool.KeepBest = false
7276
pool.NMigrate = pool.PopSize / 10

‎mlp-ea-decentralized/web/src/go/main.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func main() {
1818
logger := WebLogger{}
1919

2020
client := ga.Client{
21-
ServerAddr: "ws://127.0.0.1:3118",
21+
ServerAddr: "ws://127.0.0.1:2019",
2222
ID: "clientWasm",
2323
Log: logrus.New(),
2424
Delegate: mlp.DelegateImpl{},
87.6 KB
Binary file not shown.

0 commit comments

Comments
 (0)