Skip to content
Snippets Groups Projects
Unverified Commit f04c22b2 authored by Wolfgang Welz's avatar Wolfgang Welz Committed by GitHub
Browse files

Remove graph plugin (#388)

* remove submodules

* remove graph plugin

* remove graph plugin from configs and texts
parent 33585517
No related branches found
No related tags found
No related merge requests found
[submodule "IOTAtangle"]
path = IOTAtangle
url = https://github.com/glumb/IOTAtangle.git
[submodule "socket.io-client"]
path = socket.io-client
url = https://github.com/socketio/socket.io-client.git
Subproject commit 07bba77a296a2d06277cdae56aa963abeeb5f66e
......@@ -172,7 +172,7 @@ If Go is installed, you should see the version that's installed.
When you first run GoShimmer, the node starts running and tries to connects to neighbors, using the autopeering module.
To run other modules such as the `spammer` or the Glumb visualizer `graph`, you can configure GoShimmer to enable them through plugins.
To run other modules such as the `spammer`, you can configure GoShimmer to enable them through plugins.
**Note:** For a list of all the available configuration parameters, you can run the following command:
......@@ -211,31 +211,6 @@ To access the dashboard, you can use your browser (the default address is `http:
![dashboard](images/dashboard.png "Dashboard")
### Installing the Glumb visualizer
The Glumb visualizer allows you to view the transactions in the network, using a web browser.
1. Enable the `graph` plugin either in your `config.json` file or in the command line (`--node.enablePlugins=["graph"]`)
2. If you're running GoShimmer with the precompiled executable file, do the following in the `goshimmer` directory:
```bash
git clone https://github.com/glumb/IOTAtangle.git
// only this version seems to be stable
cd IOTAtangle && git reset --hard 07bba77a296a2d06277cdae56aa963abeeb5f66e
cd ../
git clone https://github.com/socketio/socket.io-client.git
```
3. If you built the code from source, do the following in the `goshimmer` directory:
```bash
git submodule init
git submodule update
```
To open the visualizer, run GoShimmer, and go to `127.0.0.1:8083` in a web browser.
## Supporting the project
If you want to contribute to the code, consider posting a [bug report](https://github.com/iotaledger/goshimmer/issues/new-issue), feature request or a [pull request](https://github.com/iotaledger/goshimmer/pulls/).
......
......@@ -37,13 +37,6 @@
"gossip": {
"port": 14666
},
"graph": {
"bindAddress": "127.0.0.1:8082",
"domain": "",
"networkName": "GoShimmer",
"socketIOPath": "socket.io-client/dist/socket.io.js",
"webrootPath": "IOTAtangle/webroot"
},
"logger": {
"level": "info",
"disableCaller": false,
......
......@@ -21,10 +21,8 @@ services:
# autopeering: - "14626:14626/udp"
# webAPI: - "8080:8080/tcp"
# dashboard: - "8081:8081/tcp"
# graph: - "8082:8082/tcp"
ports:
- "14666:14666/tcp"
- "14626:14626/udp"
#- "8080:8080/tcp"
#- "8081:8081/tcp"
#- "8082:8082/tcp"
......@@ -2,11 +2,9 @@ package ui
import (
"github.com/iotaledger/goshimmer/plugins/dashboard"
"github.com/iotaledger/goshimmer/plugins/graph"
"github.com/iotaledger/hive.go/node"
)
var PLUGINS = node.Plugins(
dashboard.Plugin,
graph.Plugin,
)
# How to install this plugin
- Run the following commands in this folder (or set `graph.socketioPath` and `graph.webrootPath` in your config if you want to use another path)
```bash
git clone https://github.com/glumb/IOTAtangle.git
cd IOTAtangle && git reset --hard 07bba77a296a2d06277cdae56aa963abeeb5f66e
cd ../
git clone https://github.com/socketio/socket.io-client.git
```
\ No newline at end of file
package graph
import (
"container/ring"
"fmt"
"strings"
socketio "github.com/googollee/go-socket.io"
"github.com/iotaledger/goshimmer/packages/binary/messagelayer/message"
"github.com/iotaledger/iota.go/consts"
"github.com/iotaledger/goshimmer/plugins/config"
"github.com/iotaledger/hive.go/syncutils"
)
const (
MessageBufferSize = 1800
)
var (
msgRingBuffer *ring.Ring // messages
snRingBuffer *ring.Ring // confirmed messages
msRingBuffer *ring.Ring // Milestones
broadcastLock = syncutils.Mutex{}
msgRingBufferLock = syncutils.Mutex{}
)
type wsMessage struct {
Hash string `json:"hash"`
Address string `json:"address"`
Value string `json:"value"`
Tag string `json:"tag"`
Timestamp string `json:"timestamp"`
CurrentIndex string `json:"current_index"`
LastIndex string `json:"last_index"`
Bundle string `json:"bundle_hash"`
TrunkMessageId string `json:"transaction_trunk"`
BranchMessageId string `json:"transaction_branch"`
}
type wsMessageSn struct {
Hash string `json:"hash"`
Address string `json:"address"`
TrunkMessageId string `json:"transaction_trunk"`
BranchMessageId string `json:"transaction_branch"`
Bundle string `json:"bundle"`
}
type wsConfig struct {
NetworkName string `json:"networkName"`
}
func initRingBuffers() {
msgRingBuffer = ring.New(MessageBufferSize)
snRingBuffer = ring.New(MessageBufferSize)
msRingBuffer = ring.New(20)
}
func onConnectHandler(s socketio.Conn) error {
infoMsg := "Graph client connection established"
if s != nil {
infoMsg = fmt.Sprintf("%s (ID: %v)", infoMsg, s.ID())
}
log.Info(infoMsg)
socketioServer.JoinRoom("broadcast", s)
config := &wsConfig{NetworkName: config.Node.GetString(CFG_NETWORK)}
var initMsgs []*wsMessage
msgRingBuffer.Do(func(wsMsg interface{}) {
if wsMsg != nil {
initMsgs = append(initMsgs, wsMsg.(*wsMessage))
}
})
var initSns []*wsMessageSn
snRingBuffer.Do(func(sn interface{}) {
if sn != nil {
initSns = append(initSns, sn.(*wsMessageSn))
}
})
var initMs []string
msRingBuffer.Do(func(ms interface{}) {
if ms != nil {
initMs = append(initMs, ms.(string))
}
})
s.Emit("config", config)
s.Emit("inittx", initMsgs) // needs to be 'tx' for now
s.Emit("initsn", initSns)
s.Emit("initms", initMs)
s.Emit("donation", "0")
s.Emit("donations", []int{})
s.Emit("donation-address", "-")
return nil
}
func onErrorHandler(conn socketio.Conn, e error) {
errorMsg := "Graph meet error"
if e != nil {
errorMsg = fmt.Sprintf("%s: %s", errorMsg, e.Error())
}
log.Error(errorMsg)
}
func onDisconnectHandler(s socketio.Conn, msg string) {
infoMsg := "Graph client connection closed"
if s != nil {
infoMsg = fmt.Sprintf("%s (ID: %v)", infoMsg, s.ID())
}
log.Info(fmt.Sprintf("%s: %s", infoMsg, msg))
socketioServer.LeaveAllRooms(s)
}
var emptyTag = strings.Repeat("9", consts.TagTrinarySize/3)
func onAttachedMessage(msg *message.Message) {
wsMsg := &wsMessage{
Hash: msg.Id().String(),
Address: "",
Value: "0",
Tag: emptyTag,
Timestamp: "0",
CurrentIndex: "0",
LastIndex: "0",
Bundle: consts.NullHashTrytes,
TrunkMessageId: msg.TrunkId().String(),
BranchMessageId: msg.BranchId().String(),
}
msgRingBufferLock.Lock()
msgRingBuffer.Value = wsMsg
msgRingBuffer = msgRingBuffer.Next()
msgRingBufferLock.Unlock()
broadcastLock.Lock()
// needs to use 'tx' for now
socketioServer.BroadcastToRoom("broadcast", "tx", wsMsg)
broadcastLock.Unlock()
}
package graph
import (
"github.com/iotaledger/goshimmer/plugins/banner"
flag "github.com/spf13/pflag"
)
const (
CFG_WEBROOT = "graph.webrootPath"
CFG_SOCKET_IO = "graph.socketioPath"
CFG_DOMAIN = "graph.domain"
CFG_BIND_ADDRESS = "graph.bindAddress"
CFG_NETWORK = "graph.networkName"
)
func init() {
flag.String(CFG_WEBROOT, "IOTAtangle/webroot", "Path to IOTA Tangle Visualiser webroot files")
flag.String(CFG_SOCKET_IO, "socket.io-client/dist/socket.io.js", "Path to socket.io.js")
flag.String(CFG_DOMAIN, "", "Set the domain on which IOTA Tangle Visualiser is served")
flag.String(CFG_BIND_ADDRESS, "127.0.0.1:8082", "the bind address for the IOTA Tangle Visualizer")
flag.String(CFG_NETWORK, banner.AppName, "Name of the network shown in IOTA Tangle Visualiser")
}
package graph
import (
"errors"
"net/http"
"time"
"github.com/iotaledger/goshimmer/packages/binary/messagelayer/message"
"github.com/iotaledger/goshimmer/plugins/config"
"github.com/iotaledger/goshimmer/plugins/messagelayer"
"golang.org/x/net/context"
"github.com/iotaledger/goshimmer/packages/shutdown"
engineio "github.com/googollee/go-engine.io"
"github.com/googollee/go-engine.io/transport"
"github.com/googollee/go-engine.io/transport/polling"
"github.com/googollee/go-engine.io/transport/websocket"
socketio "github.com/googollee/go-socket.io"
"github.com/iotaledger/hive.go/daemon"
"github.com/iotaledger/hive.go/events"
"github.com/iotaledger/hive.go/logger"
"github.com/iotaledger/hive.go/node"
"github.com/iotaledger/hive.go/workerpool"
)
// PluginName is the name of the graph plugin.
const PluginName = "Graph"
var (
// Plugin is the plugin instance of the graph plugin.
Plugin = node.NewPlugin(PluginName, node.Disabled, configure, run)
log *logger.Logger
newMsgWorkerCount = 1
newMsgWorkerQueueSize = 10000
newMsgWorkerPool *workerpool.WorkerPool
server *http.Server
router *http.ServeMux
socketioServer *socketio.Server
)
func downloadSocketIOHandler(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, config.Node.GetString(CFG_SOCKET_IO))
}
func configureSocketIOServer() error {
var err error
socketioServer, err = socketio.NewServer(&engineio.Options{
PingTimeout: time.Second * 20,
PingInterval: time.Second * 5,
Transports: []transport.Transport{
polling.Default,
websocket.Default,
},
})
if err != nil {
return err
}
socketioServer.OnConnect("/", onConnectHandler)
socketioServer.OnError("/", onErrorHandler)
socketioServer.OnDisconnect("/", onDisconnectHandler)
return nil
}
func configure(plugin *node.Plugin) {
log = logger.NewLogger(PluginName)
initRingBuffers()
router = http.NewServeMux()
// socket.io and web server
server = &http.Server{
Addr: config.Node.GetString(CFG_BIND_ADDRESS),
Handler: router,
}
fs := http.FileServer(http.Dir(config.Node.GetString(CFG_WEBROOT)))
if err := configureSocketIOServer(); err != nil {
log.Panicf("%v", err.Error())
}
router.Handle("/", fs)
router.HandleFunc("/socket.io/socket.io.js", downloadSocketIOHandler)
router.Handle("/socket.io/", socketioServer)
newMsgWorkerPool = workerpool.New(func(task workerpool.Task) {
onAttachedMessage(task.Param(0).(*message.Message))
task.Return(nil)
}, workerpool.WorkerCount(newMsgWorkerCount), workerpool.QueueSize(newMsgWorkerQueueSize))
}
func run(*node.Plugin) {
onMessageAttached := events.NewClosure(func(msg *message.Message) {
newMsgWorkerPool.TrySubmit(msg)
})
daemon.BackgroundWorker("Graph[AttachedMessageWorker]", func(shutdownSignal <-chan struct{}) {
log.Info("Starting Graph[AttachedMessageWorker] ... done")
messagelayer.Tangle.Events.MessageAttached.Attach(onMessageAttached)
newMsgWorkerPool.Start()
<-shutdownSignal
messagelayer.Tangle.Events.MessageAttached.Detach(onMessageAttached)
newMsgWorkerPool.Stop()
log.Info("Stopping Graph[AttachedMessageWorker] ... done")
}, shutdown.PriorityGraph)
daemon.BackgroundWorker("Graph Webserver", func(shutdownSignal <-chan struct{}) {
go socketioServer.Serve()
stopped := make(chan struct{})
go func() {
log.Infof("You can now access IOTA Tangle Visualiser using: http://%s", config.Node.GetString(CFG_BIND_ADDRESS))
if err := server.ListenAndServe(); err != nil {
if !errors.Is(err, http.ErrServerClosed) {
log.Errorf("Error serving: %s", err)
}
}
close(stopped)
}()
select {
case <-shutdownSignal:
case <-stopped:
}
log.Info("Stopping Graph Webserver ...")
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
if err := server.Shutdown(ctx); err != nil {
log.Errorf("Error stopping: %s", err)
}
if err := socketioServer.Close(); err != nil {
log.Errorf("Error closing Socket.IO server: %s", err)
}
log.Info("Stopping Graph Webserver ... done")
}, shutdown.PriorityGraph)
}
......@@ -49,7 +49,6 @@ func configure(_ *node.Plugin) {
// "Logger"
// ],
// "disabledlugins":[
// "Graph",
// "RemoteLog",
// "Spammer",
// "WebAPI Auth"
......
Subproject commit 661f1e7fac2488b6d3d206f96bb59073c4c98b1c
......@@ -33,13 +33,6 @@
"gossip": {
"port": 14666
},
"graph": {
"bindAddress": "127.0.0.1:8082",
"domain": "",
"networkName": "GoShimmer",
"socketIOPath": "socket.io-client/dist/socket.io.js",
"webrootPath": "IOTAtangle/webroot"
},
"logger": {
"level": "info",
"disableCaller": false,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment