github.com/celestiaorg/celestia-node@v0.15.0-beta.1/share/p2p/shrexeds/params.go (about)

     1  package shrexeds
     2  
     3  import (
     4  	"fmt"
     5  
     6  	logging "github.com/ipfs/go-log/v2"
     7  
     8  	"github.com/celestiaorg/celestia-node/share/p2p"
     9  )
    10  
    11  const protocolString = "/shrex/eds/v0.0.1"
    12  
    13  var log = logging.Logger("shrex/eds")
    14  
    15  // Parameters is the set of parameters that must be configured for the shrex/eds protocol.
    16  type Parameters struct {
    17  	*p2p.Parameters
    18  
    19  	// BufferSize defines the size of the buffer used for writing an ODS over the stream.
    20  	BufferSize uint64
    21  }
    22  
    23  func DefaultParameters() *Parameters {
    24  	return &Parameters{
    25  		Parameters: p2p.DefaultParameters(),
    26  		BufferSize: 32 * 1024,
    27  	}
    28  }
    29  
    30  func (p *Parameters) Validate() error {
    31  	if p.BufferSize <= 0 {
    32  		return fmt.Errorf("invalid buffer size: %v, value should be positive and non-zero", p.BufferSize)
    33  	}
    34  
    35  	return p.Parameters.Validate()
    36  }
    37  
    38  func (c *Client) WithMetrics() error {
    39  	metrics, err := p2p.InitClientMetrics("eds")
    40  	if err != nil {
    41  		return fmt.Errorf("shrex/eds: init Metrics: %w", err)
    42  	}
    43  	c.metrics = metrics
    44  	return nil
    45  }
    46  
    47  func (s *Server) WithMetrics() error {
    48  	metrics, err := p2p.InitServerMetrics("eds")
    49  	if err != nil {
    50  		return fmt.Errorf("shrex/eds: init Metrics: %w", err)
    51  	}
    52  	s.metrics = metrics
    53  	return nil
    54  }