sdk

package
v0.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 13, 2023 License: Apache-2.0 Imports: 6 Imported by: 1

README

BitTwister SDK for Go

The BitTwister SDK for Go provides a convenient interface to interact with the BitTwister tool, which applies network restrictions on a network interface, including bandwidth limitation, packet loss, latency, and jitter.

Installation

To use this SDK, import it into your Go project:

go get -u github.com/celestiaorg/bittwister/sdk

Usage

Initialization

First, import the SDK into your Go project:

import "github.com/celestiaorg/bittwister/sdk"

Next, create a client by specifying the base URL of where BitTwister is running e.g. a container running on the same machine:

func main() {
  baseURL := "http://localhost:9007/api/v1"
  client := sdk.NewClient(baseURL)
  // Use the client for API requests
}
Examples

Bandwidth Service

Start the Bandwidth service with a specified network interface and bandwidth limit:

req := sdk.BandwidthStartRequest{
    NetworkInterfaceName: "eth0",
    Limit:                100,
}

err := client.BandwidthStart(req)
if err != nil {
    // Handle error
}

Stop the Bandwidth service:

err := client.BandwidthStop()
if err != nil {
    // Handle error
}

Retrieve the status of the Bandwidth service:

status, err := client.BandwidthStatus()
if err != nil {
    // Handle error
}
// Use status for further processing

Similarly, you can use PacketlossStart, PacketlossStop, PacketlossStatus, LatencyStart, LatencyStop, LatencyStatus, and other functions provided by the SDK following similar usage patterns.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsErrorServiceAlreadyStarted

func IsErrorServiceAlreadyStarted(err error) bool

func IsErrorServiceNotInitialized

func IsErrorServiceNotInitialized(err error) bool

func IsErrorServiceNotReady

func IsErrorServiceNotReady(err error) bool

func IsErrorServiceNotStarted

func IsErrorServiceNotStarted(err error) bool

func IsErrorServiceStartFailed

func IsErrorServiceStartFailed(err error) bool

func IsErrorServiceStopFailed

func IsErrorServiceStopFailed(err error) bool

Types

type BandwidthStartRequest

type BandwidthStartRequest = api.BandwidthStartRequest

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(baseURL string) *Client

func (*Client) AllServicesStatus

func (c *Client) AllServicesStatus() ([]ServiceStatus, error)

func (*Client) BandwidthStart

func (c *Client) BandwidthStart(req BandwidthStartRequest) error

func (*Client) BandwidthStatus

func (c *Client) BandwidthStatus() (*MetaMessage, error)

func (*Client) BandwidthStop

func (c *Client) BandwidthStop() error

func (*Client) LatencyStart

func (c *Client) LatencyStart(req LatencyStartRequest) error

func (*Client) LatencyStatus

func (c *Client) LatencyStatus() (*MetaMessage, error)

func (*Client) LatencyStop

func (c *Client) LatencyStop() error

func (*Client) PacketlossStart

func (c *Client) PacketlossStart(req PacketLossStartRequest) error

func (*Client) PacketlossStatus

func (c *Client) PacketlossStatus() (*MetaMessage, error)

func (*Client) PacketlossStop

func (c *Client) PacketlossStop() error

type Error

type Error struct {
	Message MetaMessage
}

func (Error) Error

func (e Error) Error() string

Error returns the error message as a string

type LatencyStartRequest

type LatencyStartRequest = api.LatencyStartRequest

type MetaMessage

type MetaMessage = api.MetaMessage

type PacketLossStartRequest

type PacketLossStartRequest = api.PacketLossStartRequest

type ServiceStatus

type ServiceStatus = api.ServiceStatus

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL