Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type SimpleTimeOracle ¶
type SimpleTimeOracle struct {
// Address is the IP address of the time oracle.
Address string
// Port is the port number of the time oracle.
Port int
// MsgChan is the channel used for sending and receiving messages.
MsgChan chan string
// contains filtered or unexported fields
}
SimpleTimeOracle represents a simple time oracle that provides time-related information. It contains the address, port, base URL, server, message channel, and locker.
func NewSimpleTimeOracle ¶
func NewSimpleTimeOracle(address string, port int, locker locker.Locker) *SimpleTimeOracle
NewSimpleTimeOracle creates a new instance of SimpleTimeOracle.
func (*SimpleTimeOracle) GetTime ¶
func (s *SimpleTimeOracle) GetTime() time.Time
GetTime returns the current time as reported by the SimpleTimeOracle.
func (*SimpleTimeOracle) Start ¶
func (s *SimpleTimeOracle) Start() error
Start starts the SimpleTimeOracle server. It initializes the router and sets up the necessary routes for serving time, locking, and unlocking. It then starts the server and listens for incoming requests. Returns an error if there was a problem starting the server.
func (*SimpleTimeOracle) Stop ¶
func (s *SimpleTimeOracle) Stop() error
Stop stops the SimpleTimeOracle server gracefully. It shuts down the server and sends a message to the MsgChan indicating that the Simple Time Oracle has stopped. It returns an error if there was an issue shutting down the server.
func (*SimpleTimeOracle) WaitForStartUp ¶
func (s *SimpleTimeOracle) WaitForStartUp(timeout time.Duration) error
WaitForStartUp waits for the server to start up by continuously sending HTTP requests to the "/time" endpoint until a successful response is received or the timeout is reached. It returns an error if the server does not reply within the specified timeout duration.
type TimeOracle ¶
TimeOracle is an interface that defines a method for retrieving the current time.