Skip to content
Snippets Groups Projects
Select Git revision
  • 9351e3648306b3229bbb44446c825da7a0e0abb2
  • develop default protected
  • congestioncontrol
  • merge-v-data-collection-spammer-0.8.2
  • WIP-merge-v-data-collection-spammer-0.8.2
  • merge-v-data-collection-spammer-0.7.7
  • tmp
  • test-masterpow-fixing
  • test-masterpow
  • test-echo
  • v-data-collection
  • v-data-collection-spammer
  • tmp-dump-spam-info
  • dump-msg-info-0.3.1
  • test-dump-message-info
  • spammer-exprandom
  • extra/tutorial
  • without_tipselection
  • hacking-docker-network
  • hacking-docker-network-0.2.3
  • master
  • v0.2.3
22 results

go.mod

Blame
  • This project manages its dependencies using Go Modules. Learn more
    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"`
    }