Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var EventsToStringMap = map[EventType]string{
1: "EvtSoftStart",
2: "EvtFullStart",
3: "EvtShardMigrationStart",
4: "EvtStopShard",
5: "EvtResume",
6: "EvtShutdown",
7: "EvtGuildState",
8: "EvtSlaveHello",
9: "EvtSoftStartComplete",
10: "EvtShardStopped",
}
var EvtDataMap = map[EventType]func() interface{}{ EvtSlaveHello: func() interface{} { return new(SlaveHelloData) }, EvtShardMigrationStart: func() interface{} { return new(ShardMigrationStartData) }, EvtStopShard: func() interface{} { return new(StopShardData) }, EvtResume: func() interface{} { return new(ResumeShardData) }, EvtGuildState: func() interface{} { return new(GuildStateData) }, }
Mapping of events to structs for their data
Functions ¶
func EncodeEvent ¶
EncodeEvent encodes the event to the wire format The wire format is pretty basic, first 4 bytes is a uin32 representing what type of event this is next 4 bytes is another uin32 which represents the length of the body next n bytes is the body itself, which can even be empty in some cases
func Listen ¶
func Listen(addr string)
Listen starts listening for slave connections, it also starts the monitor that will start new slaves if none has been spotted for 15 seconds (in case of crashes and such)
func StartSlave ¶
func StartSlave()
Types ¶
type Conn ¶
type Conn struct { ID int64 // Called on incoming messages MessageHandler func(*Message) // called when the connection is closed ConnClosedHanlder func() // contains filtered or unexported fields }
Simple helper to manage the underlying connection using locks
func ConnFromNetCon ¶
ConnFromNetCon wraos a Conn around a net.Conn
func (*Conn) Send ¶
Send sends the specified message over the connection, marshaling the data using json this locks the writer
func (*Conn) SendLogErr ¶
Same as Send but logs the error (usefull for launching send in new goroutines)
func (*Conn) SendNoLock ¶
SendNoLock sends the specified message over the connection, marshaling the data using json This does no locking and the caller is responsible for making sure its not called in multiple goroutines at the same time
type EventType ¶
type EventType uint32
The event IDs are hardcoded to preserve compatibility between versions
const ( // Master -> slave EvtSoftStart EventType = 1 // Sent to signal the slave to not start anything other than start updating the state EvtFullStart EventType = 2 // Sent after a soft start event to start up everything other than the state // Sent to tell a shard that shard migration is about to happen, either to or from this shard // If from this shard to a new one, then responds with the session info needed // Otherwise, responds with no data once ready EvtShardMigrationStart EventType = 3 // Sent to tell the slave to stop a shard, responds with EvtStopShard once all state has been transfered and shard has been stopped EvtStopShard EventType = 4 // Sent to tell the slave to resume the specified shard, responds with EvtResume once finished EvtResume EventType = 5 EvtShutdown EventType = 6 // Sent to tell a slave to shut down, and immediately stop processing events, responds with the same event once shut down EvtGuildState EventType = 7 // Slave -> master EvtSlaveHello EventType = 8 EvtSoftStartComplete EventType = 9 // Sent to indicate that all shards has been connected and are waiting for the full start event EvtShardStopped EventType = 10 // Send by a slave when the shard has been stopped, includes state information for guilds related to that shardd )
type GuildStateData ¶
type GuildStateData struct {
GuildState *dstate.GuildState
}
type ResumeShardData ¶
type ShardMigrationStartData ¶
type SlaveConn ¶
type SlaveConn struct {
Conn *Conn
}
Represents a connection from a master server to a slave
func NewSlaveConn ¶
NewSlaveConn creates a new slaveconn (connection from master to slave) from a net.Conn
type SlaveHelloData ¶
type SlaveHelloData struct {
Running bool // Wether the slave was already running or not
}