diff --git a/client/message.go b/client/message.go index 68485359b24b697e06f7d6ed937a16bd99105254..267dbb343a8bea0f7c9601a3e2823babc82b697d 100644 --- a/client/message.go +++ b/client/message.go @@ -7,8 +7,7 @@ import ( ) const ( - routeFindByID = "message/findById" - routeSendPayload = "message/sendPayload" + routeFindByID = "message/findById" ) // FindMessageByID finds messages by the given base58 encoded IDs. The messages are returned in the same order as @@ -27,14 +26,3 @@ func (api *GoShimmerAPI) FindMessageByID(base58EncodedIDs []string) (*webapi_mes return res, nil } - -func (api *GoShimmerAPI) SendPayload(payload []byte) (string, error) { - - res := &webapi_message.MessageResponse{} - if err := api.do(http.MethodPost, routeSendPayload, - &webapi_message.MessageRequest{Payload: payload}, res); err != nil { - return "", err - } - - return res.ID, nil -} diff --git a/pluginmgr/research/plugins.go b/pluginmgr/research/plugins.go index 1275898c7d35401f7db62d3c804f88b50e8bd019..6e3b7bd39a3bd1cbed30585d4bd03054088ad35f 100644 --- a/pluginmgr/research/plugins.go +++ b/pluginmgr/research/plugins.go @@ -5,7 +5,6 @@ import ( analysisclient "github.com/iotaledger/goshimmer/plugins/analysis/client" analysisdashboard "github.com/iotaledger/goshimmer/plugins/analysis/dashboard" analysisserver "github.com/iotaledger/goshimmer/plugins/analysis/server" - "github.com/iotaledger/goshimmer/plugins/prometheus" "github.com/iotaledger/goshimmer/plugins/remotelog" "github.com/iotaledger/hive.go/node" ) @@ -15,6 +14,5 @@ var PLUGINS = node.Plugins( analysisserver.Plugin, analysisclient.Plugin, analysisdashboard.Plugin, - prometheus.Plugin, networkdelay.App, ) diff --git a/plugins/prometheus/data.go b/plugins/prometheus/data.go deleted file mode 100644 index 15198f47f1145d9f764104ce5ef3aa3104d76842..0000000000000000000000000000000000000000 --- a/plugins/prometheus/data.go +++ /dev/null @@ -1,50 +0,0 @@ -package prometheus - -import ( - "os" - "path/filepath" - - "github.com/iotaledger/goshimmer/plugins/config" - "github.com/iotaledger/goshimmer/plugins/database" - "github.com/prometheus/client_golang/prometheus" -) - -var ( - dataSizes *prometheus.GaugeVec -) - -func init() { - dataSizes = prometheus.NewGaugeVec( - prometheus.GaugeOpts{ - Name: "iota_data_sizes_bytes", - Help: "Data sizes in bytes.", - }, - []string{"name"}, - ) - - registry.MustRegister(dataSizes) - - addCollect(colectData) -} - -func colectData() { - dataSizes.Reset() - dbSize, err := directorySize(config.Node.GetString(database.CfgDatabaseDir)) - if err == nil { - dataSizes.WithLabelValues("database").Set(float64(dbSize)) - } -} - -func directorySize(path string) (int64, error) { - var size int64 - err := filepath.Walk(path, func(_ string, info os.FileInfo, err error) error { - if err != nil { - return err - } - if !info.IsDir() { - size += info.Size() - } - return err - }) - return size, err -} diff --git a/plugins/prometheus/info.go b/plugins/prometheus/info.go deleted file mode 100644 index 3f796c110a8e5b7bfaf6656f17d18966c3a6e56c..0000000000000000000000000000000000000000 --- a/plugins/prometheus/info.go +++ /dev/null @@ -1,35 +0,0 @@ -package prometheus - -import ( - "github.com/iotaledger/goshimmer/plugins/banner" - "github.com/prometheus/client_golang/prometheus" -) - -var ( - infoApp *prometheus.GaugeVec - infoTips prometheus.Gauge -) - -func init() { - infoApp = prometheus.NewGaugeVec( - prometheus.GaugeOpts{ - Name: "iota_info_app", - Help: "Node software name and version.", - }, - []string{"name", "version"}, - ) - infoTips = prometheus.NewGauge(prometheus.GaugeOpts{ - Name: "iota_info_tips", - Help: "Number of tips.", - }) - - infoApp.WithLabelValues(banner.AppName, banner.AppVersion).Set(1) - registry.MustRegister(infoApp) - registry.MustRegister(infoTips) - addCollect(collectInfo) -} - -func collectInfo() { - // Tips - infoTips.Set(0) -} diff --git a/plugins/prometheus/metrics.go b/plugins/prometheus/metrics.go deleted file mode 100644 index efeb6593c0c349af22b20b25dd7d27f7d27e1c78..0000000000000000000000000000000000000000 --- a/plugins/prometheus/metrics.go +++ /dev/null @@ -1,25 +0,0 @@ -package prometheus - -import ( - "github.com/iotaledger/goshimmer/plugins/metrics" - "github.com/prometheus/client_golang/prometheus" -) - -var ( - messagesPerSecond prometheus.Gauge -) - -func init() { - messagesPerSecond = prometheus.NewGauge(prometheus.GaugeOpts{ - Name: "iota_messages_per_second", - Help: "Number of messages per second.", - }) - - registry.MustRegister(messagesPerSecond) - - addCollect(collectServer) -} - -func collectServer() { - messagesPerSecond.Set(float64(metrics.ReceivedMessagesPerSecond())) -} diff --git a/plugins/prometheus/parameters.go b/plugins/prometheus/parameters.go deleted file mode 100644 index edfffadd440fbe0690b741336e7e737f7a2db866..0000000000000000000000000000000000000000 --- a/plugins/prometheus/parameters.go +++ /dev/null @@ -1,23 +0,0 @@ -package prometheus - -import ( - flag "github.com/spf13/pflag" -) - -const ( - // CfgPrometheusGoMetrics defines the config flag to enable/disable go metrics. - CfgPrometheusGoMetrics = "prometheus.goMetrics" - // CfgPrometheusProcessMetrics defines the config flag to enable/disable process metrics. - CfgPrometheusProcessMetrics = "prometheus.processMetrics" - // CfgPrometheusPromhttpMetrics defines the config flag to enable/disable promhttp metrics. - CfgPrometheusPromhttpMetrics = "prometheus.promhttpMetrics" - // CfgPrometheusBindAddress defines the config flag of the bind address on which the Prometheus exporter listens on. - CfgPrometheusBindAddress = "prometheus.bindAddress" -) - -func init() { - flag.String(CfgPrometheusBindAddress, "localhost:9311", "the bind address on which the Prometheus exporter listens on") - flag.Bool(CfgPrometheusGoMetrics, false, "include go metrics") - flag.Bool(CfgPrometheusProcessMetrics, false, "include process metrics") - flag.Bool(CfgPrometheusPromhttpMetrics, false, "include promhttp metrics") -} diff --git a/plugins/prometheus/plugin.go b/plugins/prometheus/plugin.go deleted file mode 100644 index 893e4c902aee53d5a0f78b35e1d6f724ca766e77..0000000000000000000000000000000000000000 --- a/plugins/prometheus/plugin.go +++ /dev/null @@ -1,92 +0,0 @@ -package prometheus - -import ( - "context" - "net/http" - "time" - - "github.com/gin-gonic/gin" - "github.com/iotaledger/goshimmer/packages/shutdown" - "github.com/iotaledger/goshimmer/plugins/config" - "github.com/iotaledger/hive.go/daemon" - "github.com/iotaledger/hive.go/logger" - "github.com/iotaledger/hive.go/node" - "github.com/prometheus/client_golang/prometheus" - "github.com/prometheus/client_golang/prometheus/promhttp" -) - -// Plugin Prometheus -var ( - Plugin = node.NewPlugin("Prometheus", node.Disabled, configure, run) - log *logger.Logger - - server *http.Server - registry = prometheus.NewRegistry() - collects []func() -) - -func configure(plugin *node.Plugin) { - log = logger.NewLogger(plugin.Name) - - if config.Node.GetBool(CfgPrometheusGoMetrics) { - registry.MustRegister(prometheus.NewGoCollector()) - } - if config.Node.GetBool(CfgPrometheusProcessMetrics) { - registry.MustRegister(prometheus.NewProcessCollector(prometheus.ProcessCollectorOpts{})) - } -} - -func addCollect(collect func()) { - collects = append(collects, collect) -} - -func run(plugin *node.Plugin) { - log.Info("Starting Prometheus exporter ...") - - if err := daemon.BackgroundWorker("Prometheus exporter", func(shutdownSignal <-chan struct{}) { - log.Info("Starting Prometheus exporter ... done") - - engine := gin.New() - engine.Use(gin.Recovery()) - engine.GET("/metrics", func(c *gin.Context) { - for _, collect := range collects { - collect() - } - handler := promhttp.HandlerFor( - registry, - promhttp.HandlerOpts{ - EnableOpenMetrics: true, - }, - ) - if config.Node.GetBool(CfgPrometheusPromhttpMetrics) { - handler = promhttp.InstrumentMetricHandler(registry, handler) - } - handler.ServeHTTP(c.Writer, c.Request) - }) - - bindAddr := config.Node.GetString(CfgPrometheusBindAddress) - server = &http.Server{Addr: bindAddr, Handler: engine} - - go func() { - log.Infof("You can now access the Prometheus exporter using: http://%s/metrics", bindAddr) - if err := server.ListenAndServe(); err != nil && err != http.ErrServerClosed { - log.Error("Stopping Prometheus exporter due to an error ... done") - } - }() - - <-shutdownSignal - log.Info("Stopping Prometheus exporter ...") - - if server != nil { - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) - err := server.Shutdown(ctx) - if err != nil { - log.Error(err.Error()) - } - cancel() - } - log.Info("Stopping Prometheus exporter ... done") - }, shutdown.PriorityPrometheus); err != nil { - log.Panic(err) - } -} diff --git a/plugins/webapi/message/plugin.go b/plugins/webapi/message/plugin.go index bdba4f3740deaf17d000969693b531de05c9cd5e..1ebbf8b7fb31be52efa6c59984a81e56c8218ca2 100644 --- a/plugins/webapi/message/plugin.go +++ b/plugins/webapi/message/plugin.go @@ -23,7 +23,6 @@ var ( func configure(plugin *node.Plugin) { log = logger.NewLogger(PluginName) webapi.Server.POST("message/findById", findMessageByID) - webapi.Server.POST("message/sendPayload", sendPayload) } // findMessageByID returns the array of messages for the diff --git a/plugins/webapi/message/sendPayload.go b/plugins/webapi/message/sendPayload.go deleted file mode 100644 index 1d88b6220b7ec188356e47943bf795d0559efad1..0000000000000000000000000000000000000000 --- a/plugins/webapi/message/sendPayload.go +++ /dev/null @@ -1,44 +0,0 @@ -package message - -import ( - "net/http" - - "github.com/iotaledger/goshimmer/packages/binary/messagelayer/payload" - "github.com/iotaledger/goshimmer/plugins/issuer" - "github.com/labstack/echo" -) - -// sendPayload creates a message of the given payload and -// broadcasts it to the node's neighbors. It returns the message ID if successful. -func sendPayload(c echo.Context) error { - var request MessageRequest - if err := c.Bind(&request); err != nil { - log.Info(err.Error()) - return c.JSON(http.StatusBadRequest, MessageResponse{Error: err.Error()}) - } - - //TODO: to check max payload size allowed, if exceeding return an error - - parsedPayload, _, err := payload.FromBytes(request.Payload) - if err != nil { - return c.JSON(http.StatusBadRequest, MessageResponse{Error: "not a valid payload"}) - } - - msg, err := issuer.IssuePayload(parsedPayload) - if err != nil { - return c.JSON(http.StatusBadRequest, MessageResponse{Error: err.Error()}) - } - - return c.JSON(http.StatusOK, MessageResponse{ID: msg.Id().String()}) -} - -// MessageResponse contains the ID of the message sent. -type MessageResponse struct { - ID string `json:"id,omitempty"` - Error string `json:"error,omitempty"` -} - -// MessageRequest contains the message to send. -type MessageRequest struct { - Payload []byte `json:"payload"` -} diff --git a/tools/docker-network/prometheus.yml b/tools/docker-network/prometheus.yml deleted file mode 100644 index f6fa09fdb6fcc69b0f4caa0686ee5fcd09e30992..0000000000000000000000000000000000000000 --- a/tools/docker-network/prometheus.yml +++ /dev/null @@ -1,6 +0,0 @@ -scrape_configs: - - job_name: peer_master - scrape_interval: 5s - static_configs: - - targets: - - peer_master:9311 \ No newline at end of file diff --git a/tools/double-spend/double-spend.go b/tools/double-spend/double-spend.go deleted file mode 100644 index cab37ea885be28bcfb8a47cce91812cf0b73b44d..0000000000000000000000000000000000000000 --- a/tools/double-spend/double-spend.go +++ /dev/null @@ -1,64 +0,0 @@ -package main - -import ( - "fmt" - "net/http" - "time" - - "github.com/iotaledger/goshimmer/client" - "github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/address" - "github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/address/signaturescheme" - "github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/balance" - valuepayload "github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/payload" - "github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/transaction" - "github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/wallet" - "github.com/mr-tron/base58" -) - -func main() { - - client := client.NewGoShimmerAPI("http://localhost:8080", http.Client{Timeout: 30 * time.Second}) - - // genesis wallet - genesisSeedBytes, err := base58.Decode("7R1itJx5hVuo9w9hjg5cwKFmek4HMSoBDgJZN8hKGxih") - if err != nil { - fmt.Println(err) - } - - const genesisBalance = 1000000000 - genesisWallet := wallet.New(genesisSeedBytes) - genesisAddr := genesisWallet.Seed().Address(0) - genesisOutputID := transaction.NewOutputID(genesisAddr, transaction.GenesisID) - - // issue transactions which spend the same genesis output in all partitions - conflictingTxs := make([]*transaction.Transaction, 2) - conflictingTxIDs := make([]string, 2) - receiverSeeds := make([]*wallet.Seed, 2) - for i := range conflictingTxs { - - // create a new receiver wallet for the given conflict - receiverSeeds[i] = wallet.NewSeed() - destAddr := receiverSeeds[i].Address(0) - - tx := transaction.New( - transaction.NewInputs(genesisOutputID), - transaction.NewOutputs(map[address.Address][]*balance.Balance{ - destAddr: { - {Value: genesisBalance, Color: balance.ColorIOTA}, - }, - })) - tx = tx.Sign(signaturescheme.ED25519(*genesisWallet.Seed().KeyPair(0))) - conflictingTxs[i] = tx - - valueObject := valuepayload.New(valuepayload.GenesisID, valuepayload.GenesisID, tx) - - // issue the value object - txID, err := client.SendPayload(valueObject.Bytes()) - if err != nil { - fmt.Println(err) - } - conflictingTxIDs[i] = txID - fmt.Printf("issued conflict transaction %s\n", txID) - //time.Sleep(7 * time.Second) - } -}