scnet

package
v0.3.17 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2021 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	FakeDrop    float64
	FakeLatency time.Duration
	FakeJitter  time.Duration
)

Network code testing variables.

Functions

func MockSignal

func MockSignal(ctx context.Context) (*Signal, *Signal)

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

type ExchangeDataFunc func([]byte) ([]byte, error)

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 NewGame

func NewGame(ctx context.Context) (*Game, error)

func (*Game) BeginTurn

func (g *Game) BeginTurn(ch chan<- *card.TurnData)

func (*Game) ClearRematchStatus

func (g *Game) ClearRematchStatus()

func (*Game) ExchangeInHand

func (g *Game) ExchangeInHand(data []byte) []byte

func (*Game) FinalizeMatch

func (g *Game) FinalizeMatch(verifyInit VerifyInitFunc, verifyTurn VerifyTurnFunc) error

func (*Game) LastPing

func (g *Game) LastPing() time.Duration

func (*Game) OfferRematch

func (g *Game) OfferRematch() error

func (*Game) OpponentReady

func (g *Game) OpponentReady() bool

func (*Game) RecvCosmeticData

func (g *Game) RecvCosmeticData() *card.CosmeticData

func (*Game) RecvDeck

func (g *Game) RecvDeck() (card.UnknownDeck, bool)

func (*Game) RecvInputs

func (g *Game) RecvInputs() []byte

func (*Game) RecvModifiedCards

func (g *Game) RecvModifiedCards(revealCard bool) []card.ModifiedCardPosition

func (*Game) RecvReady

func (g *Game) RecvReady(turnData *card.TurnData) bool

func (*Game) RematchStatus

func (g *Game) RematchStatus() (connected, recv, sent bool)

func (*Game) SendCosmeticData

func (g *Game) SendCosmeticData(c card.CosmeticData) error

func (*Game) SendDeck

func (g *Game) SendDeck(deck card.Deck, useEffectBack bool)

func (*Game) SendInputs

func (g *Game) SendInputs(b []byte) error

func (*Game) SendModifiedCards

func (g *Game) SendModifiedCards(m []card.ModifiedCardPosition, revealCard bool) error

func (*Game) SendQ

func (g *Game) SendQ() uint64

func (*Game) SendReady

func (g *Game) SendReady(turnData *card.TurnData)

func (*Game) State

func (g *Game) State() (ConnectionState, LogicalState)

func (*Game) UseSignal

func (g *Game) UseSignal(s *Signal, mode *string)

func (*Game) WaitAcceptRematch

func (g *Game) WaitAcceptRematch() bool

func (*Game) WaitMatchReady

func (g *Game) WaitMatchReady()

func (*Game) WaitRecvDeck

func (g *Game) WaitRecvDeck() card.UnknownDeck

func (*Game) WaitRecvReady

func (g *Game) WaitRecvReady(turnData *card.TurnData)

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
	RNGShared
	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 NewSignal

func NewSignal(ctx context.Context) (*Signal, error)

func (*Signal) Close

func (s *Signal) Close() error

func (*Signal) Init

func (s *Signal) Init(perspective Perspective, suffix string) error

func (*Signal) IsClosed

func (s *Signal) IsClosed() (websocket.StatusCode, string)

func (*Signal) Perspective

func (s *Signal) Perspective() Perspective

func (*Signal) Session

func (s *Signal) Session() string

func (*Signal) SetSession

func (s *Signal) SetSession(sess string) error

func (*Signal) WaitSession

func (s *Signal) WaitSession() string

type VerifyInitFunc

type VerifyInitFunc = func(card.Deck, card.Deck, card.UnknownDeck, []byte, []byte, []byte) error

type VerifyTurnFunc

type VerifyTurnFunc = func(seed, seed2 []byte, turn *card.TurnData) error

Jump to

Keyboard shortcuts

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