Documentation ¶
Index ¶
- Constants
- func AddTokenContext(next http.Handler) http.Handler
- func Address(message string, signature string) (string, error)
- func Compact(inputs ...interface{}) ([]byte, error)
- func Hash(message string) []byte
- func IToB(data interface{}) ([]byte, error)
- type Code
- type InitMessage
- type MatchResponse
- type Message
- type Meta
- type PlayerInfo
- type PubSubManager
- type Service
- func (s *Service) AddToMatchPool(r *MatchResponse) error
- func (s *Service) Authenticate(token *Token) (*MatchResponse, error)
- func (srv *Service) BeginVerifiedMatch(sess *Session) error
- func (srv *Service) BuildMatchVerifiedMessageWithSignature(s *Session) (*arcadeum.MatchVerifiedMessage, error)
- func (s *Service) BuildPlayerInfo(p *MatchResponse) (*PlayerInfo, error)
- func (s *Service) Close(message string, p ...*MatchResponse)
- func (s *Service) CreateSession(p *MatchResponse) (*Session, error)
- func (s *Service) FindMatch(token *Token)
- func (s *Service) HandleMatchResponses()
- func (s *Service) InitGame(uid UUID, r *MatchResponse) error
- func (s *Service) Match(rp *MatchResponse)
- func (s *Service) NewKeyedTransactor() *bind.TransactOpts
- func (s *Service) OnMessage(msg *Message) error
- func (s *Service) OnWithdrawalStarted(event *arcadeum.ArcadeumWithdrawalStarted)
- func (srv *Service) PrivKey() *ecdsa.PrivateKey
- func (s *Service) PublishToSubKey(subKey *common.Address, message Message) error
- func (s *Service) Reconnect(token *Token) (bool, error)
- func (s *Service) RemoveFromWaitingPool(resps ...*MatchResponse)
- func (s *Service) RequestTimestampProof(sess *Session) error
- func (s *Service) SendTimestampProof(p *PlayerInfo, timestamp int64) error
- func (srv *Service) Sign(inputs ...interface{}) ([]byte, error)
- func (srv *Service) SignElliptic(inputs ...interface{}) (r, s *big.Int, err error)
- func (s *Service) SubscribeToSubKey(subkey *common.Address, messages chan *Message)
- func (s *Service) VerifyTimestamp(req *arcadeum.VerifyTimestampRequest, player *PlayerInfo) (bool, error)
- type Session
- func (s *Session) FindOpponent(subKey *common.Address) *PlayerInfo
- func (s *Session) FindPlayerByAccount(account common.Address) (*PlayerInfo, error)
- func (s *Session) FindPlayerBySubKey(subKey *common.Address) *PlayerInfo
- func (s *Session) IsEmpty() bool
- func (s *Session) IsVerified() bool
- func (s *Session) IsWaiting() bool
- func (s *Session) Rank() uint32
- func (s *Session) UUID() string
- type SessionManager
- func (mgr *SessionManager) AddToMatchPool(sess *Session) error
- func (mgr *SessionManager) GetSessionByAccount(key *common.Address) (*Session, error)
- func (mgr *SessionManager) GetSessionByID(uid UUID) (*Session, error)
- func (mgr *SessionManager) GetSessionBySubKey(key *common.Address) (*Session, error)
- func (mgr *SessionManager) ReaddToMatchPool(rank uint32, uid UUID) error
- func (mgr *SessionManager) TakeRandomSessionByRank(rank uint32) (UUID, error)
- func (mgr *SessionManager) UpdateSession(sess *Session) error
- type Status
- type Token
- type UUID
Constants ¶
const ( RANK_KEY_FMT = "rank:%d" SESSION_KEY_FMT = "session:%s" ACCOUNT_KEY_FMT = "account:%s" SUBKEY_KEY_FMT = "subkey:%s" )
Variables ¶
This section is empty.
Functions ¶
func AddTokenContext ¶
Unmarshal token from query parameter and put it in request context for later retrieval and authentication logic.
Types ¶
type Code ¶
type Code int
const (
UNSUBSCRIBE Code = -100 // a internal PubSubManager message type
)
type InitMessage ¶
type InitMessage struct {
Timestamp int64 `json:"timestamp"`
}
type MatchResponse ¶
type PlayerInfo ¶
type PlayerInfo struct { Rank uint32 `json:"rank"` // Player rank as returned from Solidity pure function Index uint8 `json:"index"` // index in match session; arbitrarily set when match found and player joins a session *Token SeedHash []byte `json:"seedHash,string"` // Hash of seed as returned from Solidity pure function Account *common.Address `json:"account,string"` // owner account of signed subkey (derived from Token); See Token TimestampSig *crypto.Signature `json:"timestampSig"` // TimestampSig of session timestamp by this player Verified bool `json:"verified"` // true if the player has proven their TimestampSig }
type PubSubManager ¶
type PubSubManager struct { Channels map[string]chan *Message // subkey -> listening channel *SessionManager }
func NewPubSubManager ¶
func NewPubSubManager(smgr *SessionManager) *PubSubManager
func (*PubSubManager) Publish ¶
func (mgr *PubSubManager) Publish(channel string, msg Message) error
func (*PubSubManager) Subscribe ¶
func (mgr *PubSubManager) Subscribe(key string, channel chan *Message)
func (*PubSubManager) Unsubscribe ¶
func (mgr *PubSubManager) Unsubscribe(key string)
type Service ¶
type Service struct { ArcClient *arcadeum.Client ENV *config.ENVConfig Config *config.MatcherConfig *SessionManager *PubSubManager }
func NewService ¶
func NewService( env *config.ENVConfig, cfg *config.MatcherConfig, ethcfg *config.ETHConfig, arcconfig *config.ArcadeumConfig, rediscfg *config.RedisConfig) *Service
func (*Service) AddToMatchPool ¶
func (s *Service) AddToMatchPool(r *MatchResponse) error
func (*Service) Authenticate ¶
func (s *Service) Authenticate(token *Token) (*MatchResponse, error)
func (*Service) BeginVerifiedMatch ¶
Session has been verified so begin match and send message to each player
func (*Service) BuildMatchVerifiedMessageWithSignature ¶
func (srv *Service) BuildMatchVerifiedMessageWithSignature(s *Session) (*arcadeum.MatchVerifiedMessage, error)
func (*Service) BuildPlayerInfo ¶
func (s *Service) BuildPlayerInfo(p *MatchResponse) (*PlayerInfo, error)
func (*Service) Close ¶
func (s *Service) Close(message string, p ...*MatchResponse)
func (*Service) CreateSession ¶
func (s *Service) CreateSession(p *MatchResponse) (*Session, error)
func (*Service) HandleMatchResponses ¶
func (s *Service) HandleMatchResponses()
func (*Service) Match ¶
func (s *Service) Match(rp *MatchResponse)
Invariant: rp has been authenticated
func (*Service) NewKeyedTransactor ¶
func (s *Service) NewKeyedTransactor() *bind.TransactOpts
func (*Service) OnWithdrawalStarted ¶
func (s *Service) OnWithdrawalStarted(event *arcadeum.ArcadeumWithdrawalStarted)
Event handler when we have detected when a user has decided to withdraw money from their account
func (*Service) PrivKey ¶
func (srv *Service) PrivKey() *ecdsa.PrivateKey
func (*Service) PublishToSubKey ¶
func (*Service) RemoveFromWaitingPool ¶
func (s *Service) RemoveFromWaitingPool(resps ...*MatchResponse)
func (*Service) RequestTimestampProof ¶
func (*Service) SendTimestampProof ¶
func (s *Service) SendTimestampProof(p *PlayerInfo, timestamp int64) error
func (*Service) SignElliptic ¶
func (*Service) SubscribeToSubKey ¶
Subscribed to published messages for this player
func (*Service) VerifyTimestamp ¶
func (s *Service) VerifyTimestamp(req *arcadeum.VerifyTimestampRequest, player *PlayerInfo) (bool, error)
type Session ¶
type Session struct { ID UUID `json:"id,string"` GameID uint32 `json:"gameID"` Player1 *PlayerInfo `json:"player1"` Player2 *PlayerInfo `json:"player2"` Timestamp int64 `json:"timestamp"` // Game start in Unix time Signature *crypto.Signature `json:"signature"` // Matcher's session signature }
Represents a matched game session
func (*Session) FindOpponent ¶
func (s *Session) FindOpponent(subKey *common.Address) *PlayerInfo
func (*Session) FindPlayerByAccount ¶
func (s *Session) FindPlayerByAccount(account common.Address) (*PlayerInfo, error)
func (*Session) FindPlayerBySubKey ¶
func (s *Session) FindPlayerBySubKey(subKey *common.Address) *PlayerInfo
func (*Session) IsVerified ¶
type SessionManager ¶
type SessionManager struct { SessionPool map[UUID]*Session // map session UUID -> in-game session RedisClient *redis.Client }
func NewSessionManager ¶
func NewSessionManager(rediscfg *config.RedisConfig) *SessionManager
func (*SessionManager) AddToMatchPool ¶
func (mgr *SessionManager) AddToMatchPool(sess *Session) error
func (*SessionManager) GetSessionByAccount ¶
func (mgr *SessionManager) GetSessionByAccount(key *common.Address) (*Session, error)
func (*SessionManager) GetSessionByID ¶
func (mgr *SessionManager) GetSessionByID(uid UUID) (*Session, error)
func (*SessionManager) GetSessionBySubKey ¶
func (mgr *SessionManager) GetSessionBySubKey(key *common.Address) (*Session, error)
func (*SessionManager) ReaddToMatchPool ¶
func (mgr *SessionManager) ReaddToMatchPool(rank uint32, uid UUID) error
func (*SessionManager) TakeRandomSessionByRank ¶
func (mgr *SessionManager) TakeRandomSessionByRank(rank uint32) (UUID, error)
Find a similarly ranked player to play, pseudo-randomly chosen. Returns the UUID of the game session. This method will remove the waiting session from the wait pool. If a session is not found and there are no errors, an empty UUID is returned.
func (*SessionManager) UpdateSession ¶
func (mgr *SessionManager) UpdateSession(sess *Session) error
type Token ¶
type Token struct { GameID uint32 `json:"gameID"` // globally unique game ID SubKey *common.Address `json:"subkey,string"` // public address of account owner of subkey; effectively the Match ID SubKeySignature *crypto.Signature `json:"signature"` // Signed signature of SubKey to prove SubKey ownership Seed []byte `json:"seed,string"` // game "deck"; unmarshalled base64; never share with opponents! }
Request token. This token is returned as a base64 string by a client requesting to play a game.