Skip to content
Snippets Groups Projects
Select Git revision
  • 11162ca83c976ff1f4d9e76f3e946045ced4fb25
  • without_tipselection default
  • develop protected
  • fix/grafana-local-dashboard
  • wasp
  • fix/dashboard-explorer-freeze
  • master
  • feat/timerqueue
  • test/sync_debug_and_650
  • feat/sync_revamp_inv
  • wip/sync
  • tool/db-recovery
  • portcheck/fix
  • fix/synchronization
  • feat/new-dashboard-analysis
  • feat/refactored-analysis-dashboard
  • feat/new-analysis-dashboard
  • test/demo-prometheus-fpc
  • prometheus_metrics
  • wip/analysis-server
  • merge/fpc-test-value-transfer
  • v0.2.2
  • v0.2.1
  • v0.2.0
  • v0.1.3
  • v0.1.2
  • v0.1.1
  • v0.1.0
28 results

fpc.go

Blame
  • webapi.go 1.06 KiB
    package networkdelay
    
    import (
    	"math/rand"
    	"net/http"
    	"time"
    
    	"github.com/iotaledger/goshimmer/plugins/issuer"
    	"github.com/iotaledger/goshimmer/plugins/webapi"
    	"github.com/labstack/echo"
    )
    
    func configureWebAPI() {
    	webapi.Server().POST("networkdelay", broadcastNetworkDelayObject)
    }
    
    // broadcastNetworkDelayObject creates a message with a network delay object and
    // broadcasts it to the node's neighbors. It returns the message ID if successful.
    func broadcastNetworkDelayObject(c echo.Context) error {
    	// generate random id
    	rand.Seed(time.Now().UnixNano())
    	var id [32]byte
    	if _, err := rand.Read(id[:]); err != nil {
    		return c.JSON(http.StatusInternalServerError, Response{Error: err.Error()})
    	}
    
    	msg, err := issuer.IssuePayload(NewObject(id, time.Now().UnixNano()))
    	if err != nil {
    		return c.JSON(http.StatusBadRequest, Response{Error: err.Error()})
    	}
    	return c.JSON(http.StatusOK, Response{ID: msg.Id().String()})
    }
    
    // Response contains the ID of the message sent.
    type Response struct {
    	ID    string `json:"id,omitempty"`
    	Error string `json:"error,omitempty"`
    }