Documentation ¶
Index ¶
- Variables
- func MockSignal(ctx context.Context) (*Signal, *Signal)
- type ConnectionState
- type ExchangeDataFunc
- type Game
- func (g *Game) BeginTurn(ch chan<- *card.TurnData)
- func (g *Game) ClearRematchStatus()
- func (g *Game) ExchangeInHand(data []byte) []byte
- func (g *Game) FinalizeMatch(verifyInit VerifyInitFunc, verifyTurn VerifyTurnFunc) error
- func (g *Game) LastPing() time.Duration
- func (g *Game) OfferRematch() error
- func (g *Game) OpponentReady() bool
- func (g *Game) RecvCosmeticData() *card.CosmeticData
- func (g *Game) RecvDeck() (card.UnknownDeck, bool)
- func (g *Game) RecvInputs() []byte
- func (g *Game) RecvModifiedCards(revealCard bool) []card.ModifiedCardPosition
- func (g *Game) RecvReady(turnData *card.TurnData) bool
- func (g *Game) RematchStatus() (connected, recv, sent bool)
- func (g *Game) SendCosmeticData(c card.CosmeticData) error
- func (g *Game) SendDeck(deck card.Deck, useEffectBack bool)
- func (g *Game) SendInputs(b []byte) error
- func (g *Game) SendModifiedCards(m []card.ModifiedCardPosition, revealCard bool) error
- func (g *Game) SendQ() uint64
- func (g *Game) SendReady(turnData *card.TurnData)
- func (g *Game) State() (ConnectionState, LogicalState)
- func (g *Game) UseSignal(s *Signal, mode *string)
- func (g *Game) WaitAcceptRematch() bool
- func (g *Game) WaitMatchReady()
- func (g *Game) WaitRecvDeck() card.UnknownDeck
- func (g *Game) WaitRecvReady(turnData *card.TurnData)
- type LogicalState
- type Perspective
- type RNGSharedType
- type SecureCardGame
- func (scg *SecureCardGame) BeginTurn(exchangeData ExchangeDataFunc) (*card.TurnData, error)
- func (scg *SecureCardGame) ConfirmTurn(exchangeData ExchangeDataFunc) ([]byte, error)
- func (scg *SecureCardGame) Finalize(exchangeData ExchangeDataFunc, ...) error
- func (scg *SecureCardGame) Init(playerNumber uint8, exchangeData ExchangeDataFunc) error
- func (scg *SecureCardGame) InitTurnSeed(turnSeed, localSeed, remoteSeed []byte)
- func (scg *SecureCardGame) PrepareTurn(data []byte) ([]byte, error)
- func (scg *SecureCardGame) PromiseTurn(promise []byte) error
- func (scg *SecureCardGame) Rand(shared RNGSharedType) *rng.RNG
- func (scg *SecureCardGame) Seed(shared RNGSharedType) []byte
- func (scg *SecureCardGame) SetDeck(exchangeData ExchangeDataFunc, deck card.Deck, backs card.UnknownDeck) (card.UnknownDeck, error)
- func (scg *SecureCardGame) Shuffle(shared RNGSharedType, length int, swap func(i, j int))
- func (scg *SecureCardGame) WhenConfirmedTurn(seed2 []byte)
- type SecureCardGameOptions
- type Signal
- func (s *Signal) Close() error
- func (s *Signal) Init(perspective Perspective, suffix string) error
- func (s *Signal) IsClosed() (websocket.StatusCode, string)
- func (s *Signal) Perspective() Perspective
- func (s *Signal) Session() string
- func (s *Signal) SetSession(sess string) error
- func (s *Signal) WaitSession() string
- type VerifyInitFunc
- type VerifyTurnFunc
Constants ¶
This section is empty.
Variables ¶
Network code testing variables.
Functions ¶
Types ¶
type ConnectionState ¶
type ConnectionState uint8
const ( StateMatchmakingWait ConnectionState = iota StateConnecting StateConnected StateConnectionLost )
Constants for ConnectionState.
func (ConnectionState) String ¶
func (i ConnectionState) String() string
type ExchangeDataFunc ¶
ExchangeDataFunc is a simplified networking API where all messages are sent in both directions simultaneously.
type Game ¶
type Game struct { Perspective Perspective BetweenMatches bool SCG *SecureCardGame Cards *card.Set // contains filtered or unexported fields }
Game is the peer-to-peer game connection.
func (*Game) ClearRematchStatus ¶
func (g *Game) ClearRematchStatus()
func (*Game) ExchangeInHand ¶
func (*Game) FinalizeMatch ¶
func (g *Game) FinalizeMatch(verifyInit VerifyInitFunc, verifyTurn VerifyTurnFunc) error
func (*Game) OfferRematch ¶
func (*Game) OpponentReady ¶
func (*Game) RecvCosmeticData ¶
func (g *Game) RecvCosmeticData() *card.CosmeticData
func (*Game) RecvInputs ¶
func (*Game) RecvModifiedCards ¶
func (g *Game) RecvModifiedCards(revealCard bool) []card.ModifiedCardPosition
func (*Game) RematchStatus ¶
func (*Game) SendCosmeticData ¶
func (g *Game) SendCosmeticData(c card.CosmeticData) error
func (*Game) SendInputs ¶
func (*Game) SendModifiedCards ¶
func (g *Game) SendModifiedCards(m []card.ModifiedCardPosition, revealCard bool) error
func (*Game) State ¶
func (g *Game) State() (ConnectionState, LogicalState)
func (*Game) WaitAcceptRematch ¶
func (*Game) WaitMatchReady ¶
func (g *Game) WaitMatchReady()
func (*Game) WaitRecvDeck ¶
func (g *Game) WaitRecvDeck() card.UnknownDeck
func (*Game) WaitRecvReady ¶
type LogicalState ¶
type LogicalState uint8
const ( StateUninitialized LogicalState = iota StateSecureInitializing StateSecureReady StateMatchReady )
Constants for LogicalState.
func (LogicalState) String ¶
func (i LogicalState) String() string
type Perspective ¶
type Perspective uint8
const ( UnknownPerspective Perspective = 0 Player1 Perspective = 1 Player2 Perspective = 2 )
Constants for Perspective.
type RNGSharedType ¶
type RNGSharedType uint8
RNGSharedType determines which random number generator state is being used.
const ( RNGLocal RNGSharedType = iota RNGRemote )
Constants for RNGSharedType.
func (RNGSharedType) String ¶
func (i RNGSharedType) String() string
type SecureCardGame ¶
type SecureCardGame struct {
// contains filtered or unexported fields
}
SecureCardGame provides secrecy and verifiability to the networked card game.
func NewSecureCardGame ¶
func NewSecureCardGame(opt *SecureCardGameOptions) (*SecureCardGame, error)
NewSecureCardGame creates a SecureCardGame instance.
func (*SecureCardGame) BeginTurn ¶
func (scg *SecureCardGame) BeginTurn(exchangeData ExchangeDataFunc) (*card.TurnData, error)
BeginTurn starts a round of the card game.
func (*SecureCardGame) ConfirmTurn ¶
func (scg *SecureCardGame) ConfirmTurn(exchangeData ExchangeDataFunc) ([]byte, error)
ConfirmTurn finishes the turn and returns the opponent's promised data.
func (*SecureCardGame) Finalize ¶
func (scg *SecureCardGame) Finalize(exchangeData ExchangeDataFunc, verifyDeck func(card.Deck, card.UnknownDeck) error, verifyTurn func(*scgTurn) error) error
Finalize completes and verifies the card game.
func (*SecureCardGame) Init ¶
func (scg *SecureCardGame) Init(playerNumber uint8, exchangeData ExchangeDataFunc) error
Init starts a secure card game session.
func (*SecureCardGame) InitTurnSeed ¶
func (scg *SecureCardGame) InitTurnSeed(turnSeed, localSeed, remoteSeed []byte)
InitTurnSeed initializes the random number generator for a turn.
func (*SecureCardGame) PrepareTurn ¶
func (scg *SecureCardGame) PrepareTurn(data []byte) ([]byte, error)
PrepareTurn computes a promise for the provided data.
func (*SecureCardGame) PromiseTurn ¶
func (scg *SecureCardGame) PromiseTurn(promise []byte) error
PromiseTurn stores the opponent's promised turn data.
func (*SecureCardGame) Rand ¶
func (scg *SecureCardGame) Rand(shared RNGSharedType) *rng.RNG
Rand returns the *rng.RNG for the specified random state type.
func (*SecureCardGame) Seed ¶
func (scg *SecureCardGame) Seed(shared RNGSharedType) []byte
Seed returns the seed for the specified random state type.
func (*SecureCardGame) SetDeck ¶
func (scg *SecureCardGame) SetDeck(exchangeData ExchangeDataFunc, deck card.Deck, backs card.UnknownDeck) (card.UnknownDeck, error)
SetDeck sets the current player's deck and returns the backs of the opponent's cards.
func (*SecureCardGame) Shuffle ¶
func (scg *SecureCardGame) Shuffle(shared RNGSharedType, length int, swap func(i, j int))
Shuffle shuffles an arbitrary set of data.
func (*SecureCardGame) WhenConfirmedTurn ¶
func (scg *SecureCardGame) WhenConfirmedTurn(seed2 []byte)
WhenConfirmedTurn initializes the shared seed for the processing stage of a round of Spy Cards Online.
type SecureCardGameOptions ¶
type SecureCardGameOptions struct { NewHash func() hash.Hash SeedLength int RandLength int ForReplay *[3]uint64 }
SecureCardGameOptions modifies the behavior of SecureCardGame.
type Signal ¶
type Signal struct {
// contains filtered or unexported fields
}
Signal is a connection to the signaling server.
func (*Signal) Perspective ¶
func (s *Signal) Perspective() Perspective