Documentation ¶
Index ¶
- Constants
- Variables
- type AddSessionRequest
- type GeoIP2Domain
- type MitmDomain
- type MitmInfo
- type SessionDomain
- func (d *SessionDomain) Add(request *AddSessionRequest, ip net.IP) (*entity.Session, error)
- func (d *SessionDomain) Get(roomID int32) (*entity.Session, error)
- func (d *SessionDomain) GetTunnel(tunnelName string) *MitmInfo
- func (d *SessionDomain) List() ([]entity.Session, error)
- func (d *SessionDomain) PurgeOld() error
- type SessionRepository
- type ValidationDomain
Constants ¶
const ( SessionCreate requestType = iota SessionUpdate SessionTouch )
SessionAddType enum value
const RateLimit = 5
RateLimit is the maximal rate a client can send an update (every five seconds)
const SessionDeadline = 60
SessionDeadline is lifespan of a session that hasn't recieved any updated in seconds.
Variables ¶
var ErrRateLimited = errors.New("Rate limit reached")
ErrRateLimited is thrown when the rate limit is reached for a particular session.
var ErrSessionRejected = errors.New("Session rejected")
ErrSessionRejected is thrown when a session got rejected by the domain logic.
Functions ¶
This section is empty.
Types ¶
type AddSessionRequest ¶
type AddSessionRequest struct { Username string `form:"username"` CoreName string `form:"core_name"` CoreVersion string `form:"core_version"` GameName string `form:"game_name"` GameCRC string `form:"game_crc"` Port uint16 `form:"port"` MITMServer string `form:"mitm_server"` HasPassword bool `form:"has_password"` // 1/0 (Can it be bound to bool?) HasSpectatePassword bool `form:"has_spectate_password"` ForceMITM bool `form:"force_mitm"` RetroArchVersion string `form:"retroarch_version"` Frontend string `form:"frontend"` SubsystemName string `form:"subsystem_name"` MITMSession string `form:"mitm_session"` MITMCustomServer string `form:"mitm_custom_addr"` MITMCustomPort uint16 `form:"mitm_custom_port"` }
AddSessionRequest defines the request for the SessionDomain.Add() request.
type GeoIP2Domain ¶
type GeoIP2Domain struct {
// contains filtered or unexported fields
}
GeoIP2Domain abstracts the GeoIP2 country database domain logic.
func NewGeoIP2Domain ¶
func NewGeoIP2Domain(path string) (*GeoIP2Domain, error)
NewGeoIP2Domain creates a new domain object for the GeoIP2 country database. Need the path to a maxminddb file.
func (*GeoIP2Domain) Close ¶
func (d *GeoIP2Domain) Close()
Close needs to be called to properly close the internal maxminddb database.
func (*GeoIP2Domain) GetCountryCodeForIP ¶
func (d *GeoIP2Domain) GetCountryCodeForIP(ip net.IP) (string, error)
GetCountryCodeForIP returns the two letter country code (ISO 3166-1) for the given IP.
type MitmDomain ¶
type MitmDomain struct {
// contains filtered or unexported fields
}
MitmDomain abstracts the mitm logic for handling netplay relays.
func NewMitmDomain ¶
func NewMitmDomain(servers map[string]string) *MitmDomain
NewMitmDomain creates a new MITM domain logic.
func (*MitmDomain) GetInfo ¶
func (d *MitmDomain) GetInfo(handle string) *MitmInfo
GetInfo translates a MITM server handle into an address/port pair.
type MitmInfo ¶
MitmInfo represents a relay server info.
func (*MitmInfo) PrintForRetroarch ¶
PrintForRetroarch prints out the MITM information in a format that retroarch is expecting.
type SessionDomain ¶
type SessionDomain struct {
// contains filtered or unexported fields
}
SessionDomain abstracts the domain logic for netplay session handling.
func NewSessionDomain ¶
func NewSessionDomain( sessionRepo SessionRepository, geoIP2Domain *GeoIP2Domain, validationDomain *ValidationDomain, mitmDomain *MitmDomain) *SessionDomain
NewSessionDomain returns an initalized SessionDomain struct.
func (*SessionDomain) Add ¶
func (d *SessionDomain) Add(request *AddSessionRequest, ip net.IP) (*entity.Session, error)
Add adds or updates a session, based on the incoming request from the given IP. Returns ErrSessionRejected if session got rejected. Returns ErrRateLimited if rate limit for a session got reached.
func (*SessionDomain) Get ¶
func (d *SessionDomain) Get(roomID int32) (*entity.Session, error)
Get returns the session with the given RoomID
func (*SessionDomain) GetTunnel ¶
func (d *SessionDomain) GetTunnel(tunnelName string) *MitmInfo
GetTunnel returns a tunnel's address/port pair.
func (*SessionDomain) List ¶
func (d *SessionDomain) List() ([]entity.Session, error)
List returns a list of all sessions that are currently being hosted
func (*SessionDomain) PurgeOld ¶
func (d *SessionDomain) PurgeOld() error
PurgeOld removes all sessions that have not been updated for longer than 45 seconds.
type SessionRepository ¶
type SessionRepository interface { Create(s *entity.Session) error GetByID(id string) (*entity.Session, error) GetByRoomID(roomID int32) (*entity.Session, error) GetAll(deadline time.Time) ([]entity.Session, error) Update(s *entity.Session) error Touch(id string) error PurgeOld(deadline time.Time) error }
SessionRepository interface to decouple the domain logic from the repository code.
type ValidationDomain ¶
type ValidationDomain struct {
// contains filtered or unexported fields
}
ValidationDomain provides the domain logic for session validation
func NewValidationDomain ¶
func NewValidationDomain(stringBlacklist []string, ipBlacklist []string) (*ValidationDomain, error)
NewValidationDomain creates a new initalized Validation domain logic struct.
func (*ValidationDomain) ValdateIP ¶
func (d *ValidationDomain) ValdateIP(ip net.IP) bool
ValdateIP validates an IP address against a IP blacklist. The validation has linear complexity.
func (*ValidationDomain) ValidateString ¶
func (d *ValidationDomain) ValidateString(s string) bool
ValidateString validates a string against a regexp based blacklist and other rulesets. The validation has linear complexity.