entity

package
v1.0.0-SNAPSHOT...-0150756 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2018 License: Apache-2.0 Imports: 12 Imported by: 9

Documentation

Overview

* Copyright 2018 Johannes Donath <johannesd@torchmind.com> * and other copyright owners as documented in the project's IP log. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.

* Copyright 2018 Johannes Donath <johannesd@torchmind.com> * and other copyright owners as documented in the project's IP log. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.

* Copyright 2018 Johannes Donath <johannesd@torchmind.com> * and other copyright owners as documented in the project's IP log. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.

* Copyright 2018 Johannes Donath <johannesd@torchmind.com> * and other copyright owners as documented in the project's IP log. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.

* Copyright 2018 Johannes Donath <johannesd@torchmind.com> * and other copyright owners as documented in the project's IP log. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.

* Copyright 2018 Johannes Donath <johannesd@torchmind.com> * and other copyright owners as documented in the project's IP log. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.

* Copyright 2018 Johannes Donath <johannesd@torchmind.com> * and other copyright owners as documented in the project's IP log. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.

Index

Constants

View Source
const NameChangeRateLimitPeriod = time.Hour * 24 * 30

defines the total amount of time that has to pass before a user can choose a new name again

View Source
const NameValidityPeriod = time.Hour * 24 * 37

defines the total amount of time a name can be safely associated with a given profile

Variables

View Source
var IntroductoryValidityPeriodEnd = time.Unix(1425600000, 0)

defines the date and time at which initial account names are set to expired this is set to the time of introduction (4th of January 2015) + 30 days (for safety we will not be using the full 37 grace period here)

Functions

func CalculateNameGracePeriodBeginning

func CalculateNameGracePeriodBeginning(end time.Time) time.Time

calculates the beginning of a theoretical grace period

func CalculateNameGracePeriodEnd

func CalculateNameGracePeriodEnd(start time.Time) time.Time

calculates the end of a theoretical grace period

func IsMojangId

func IsMojangId(id string) bool

Evaluates whether the passed ID is a mojang identifier

func IsNameAssociationValid

func IsNameAssociationValid(lastSeen time.Time) bool

evaluates whether a given name association is still considered valid (e.g. no other user was able to claim the name since it was last encountered)

func IsNameAssociationValidAt

func IsNameAssociationValidAt(at time.Time, lastSeen time.Time) bool

evaluates whether a given name association is still considered valid (e.g. no other user was able to claim the name since it was last encountered)

func IsProfileId

func IsProfileId(id string) bool

evaluates whether the passed string is a profileId TODO: This is only used by the legacy API

func ParseId

func ParseId(id string) (uuid.UUID, error)

Parses an identifier (regardless of whether it is supplied in its Mojang or standard format)

func SerializeNameChangeArray

func SerializeNameChangeArray(history []*NameChange) ([]byte, error)

func SerializeProfileIdArray

func SerializeProfileIdArray(profileIds []*ProfileId) ([]byte, error)

func ToMojangId

func ToMojangId(id uuid.UUID) string

Converts a standard UUID into its Mojang format

func ToStandardId

func ToStandardId(id string) (uuid.UUID, error)

Converts a Mojang UUID into its RFC format

func ToStandardIdString

func ToStandardIdString(id string) (string, error)

Converts a Mojang UUID into its RFC format

Types

type Blacklist

type Blacklist struct {
	Hashes []string
}

represents a server blacklist

func NewBlacklist

func NewBlacklist(hashes []string) (*Blacklist, error)

creates a new blacklist from the supplied list of hashes

func (*Blacklist) Contains

func (b *Blacklist) Contains(hash string) bool

evaluates whether a certain hash is part of a blacklist

func (*Blacklist) Deserialize

func (b *Blacklist) Deserialize(enc []byte) error

func (*Blacklist) IsBlacklisted

func (b *Blacklist) IsBlacklisted(addr string) (bool, error)

evaluates whether the passed hostname has been blacklisted

func (*Blacklist) IsBlacklistedDomain

func (b *Blacklist) IsBlacklistedDomain(hostname string) (bool, error)

evaluates whether a given hostname has been blacklisted

func (*Blacklist) IsBlacklistedIP

func (b *Blacklist) IsBlacklistedIP(ip string) (bool, error)

evaluates whether a given IPv4 address has been blacklisted

func (*Blacklist) Serialize

func (b *Blacklist) Serialize() ([]byte, error)

type Event

type Event struct {
	Type   EventType
	Key    interface{}
	Object interface{}
}

represents an even which has occurred within the cache

func (*Event) BlacklistPayload

func (e *Event) BlacklistPayload() (*Blacklist, error)

func (*Event) IdKey

func (e *Event) IdKey() (*uuid.UUID, error)

func (*Event) NameChangeHistoryPayload

func (e *Event) NameChangeHistoryPayload() (*NameChangeHistory, error)

func (*Event) ProfileIdKey

func (e *Event) ProfileIdKey() (*ProfileIdKey, error)

func (*Event) ProfileIdPayload

func (e *Event) ProfileIdPayload() (*ProfileId, error)

func (*Event) ProfilePayload

func (e *Event) ProfilePayload() (*Profile, error)

type EventType

type EventType int32

indicates which type of data is changed as part of an event

const (
	ProfileIdEvent   EventType = 0
	NameHistoryEvent EventType = 1
	ProfileEvent     EventType = 2
	BlacklistEvent   EventType = 3
)

type NameChange

type NameChange struct {
	Name        string
	ChangedToAt time.Time
	ValidUntil  time.Time
}

represents a single name change within a profile's history note that changedToAt and validUntil may be set to UNIX epoch when the entry represents the initial account name

func DeserializeNameChangeArray

func DeserializeNameChangeArray(enc []byte) ([]*NameChange, error)

func ReadNameChangeArray

func ReadNameChangeArray(reader io.Reader) ([]*NameChange, error)

func (*NameChange) Deserialize

func (p *NameChange) Deserialize(enc []byte) error

func (*NameChange) Read

func (p *NameChange) Read(reader io.Reader) error

func (*NameChange) Serialize

func (p *NameChange) Serialize() ([]byte, error)

type NameChangeHistory

type NameChangeHistory struct {
	History []*NameChange
}

encapsulates a name history

func (*NameChangeHistory) Deserialize

func (h *NameChangeHistory) Deserialize(enc []byte) error

func (*NameChangeHistory) Read

func (h *NameChangeHistory) Read(reader io.Reader) error

func (*NameChangeHistory) Serialize

func (h *NameChangeHistory) Serialize() ([]byte, error)

type Profile

type Profile struct {
	Id         uuid.UUID
	Name       string
	Properties map[string]*ProfileProperty
	Textures   *ProfileTextures
}

func (*Profile) Deserialize

func (p *Profile) Deserialize(enc []byte) error

func (*Profile) Mojang

func (p *Profile) Mojang() ([]byte, error)

converts a profile into its original REST representation TODO: this implementation is used purely for the legacy API and should be removed once the legacy API has been removed

func (*Profile) Read

func (p *Profile) Read(reader io.Reader) error

func (*Profile) Serialize

func (p *Profile) Serialize() ([]byte, error)

type ProfileId

type ProfileId struct {
	Id          uuid.UUID
	Name        string
	FirstSeenAt time.Time
	LastSeenAt  time.Time
	ValidUntil  time.Time
}

represents a single profile id mapping between a display name and a mapping at a given time note that lastSeenAt and validUntil may be set to UNIX epoch if the initial mapping is requested

func DeserializeProfileIdArray

func DeserializeProfileIdArray(enc []byte) ([]*ProfileId, error)

func ReadProfileIdArray

func ReadProfileIdArray(reader io.Reader) ([]*ProfileId, error)

func (*ProfileId) Deserialize

func (p *ProfileId) Deserialize(enc []byte) error

func (*ProfileId) IsOverlappingWith

func (p *ProfileId) IsOverlappingWith(other *ProfileId) bool

evaluates whether two profileIds theoretically overlap

two profiles are considered to overlap if their validity period overlaps at any point in time or if their assignments are equal while less than 30 days have passed (e.g. it is impossible for another user to claim and unclaim the name in the meantime due to the grace period) TODO: I have no clue how and whether Mojang handles theft of names with content creators

func (*ProfileId) IsValid

func (p *ProfileId) IsValid(at time.Time) bool

evaluates whether the profile is still valid at the given time

func (*ProfileId) Read

func (p *ProfileId) Read(reader io.Reader, at time.Time) error

func (*ProfileId) Serialize

func (p *ProfileId) Serialize() ([]byte, error)

func (*ProfileId) UpdateDiscovery

func (p *ProfileId) UpdateDiscovery(at time.Time)

updates the time at which this id has been discovered

func (*ProfileId) UpdateExpiration

func (p *ProfileId) UpdateExpiration(seen time.Time)

updates the last time at which this id has been encountered and the respective expiration times if the passed time is set before the current last encounter, the method will return immediately without changing the profile state

type ProfileIdKey

type ProfileIdKey struct {
	Name string
	At   time.Time
}

type ProfileProperty

type ProfileProperty struct {
	Name      string `json:"name"`
	Value     string `json:"value"`
	Signature string `json:"signature"`
}

func (*ProfileProperty) Deserialize

func (p *ProfileProperty) Deserialize(enc []byte) error

func (*ProfileProperty) Serialize

func (p *ProfileProperty) Serialize() ([]byte, error)

type ProfileTextures

type ProfileTextures struct {
	Timestamp   time.Time
	ProfileId   uuid.UUID
	ProfileName string
	Textures    map[string]string
}

func (*ProfileTextures) Deserialize

func (t *ProfileTextures) Deserialize(enc []byte) error

func (*ProfileTextures) Read

func (t *ProfileTextures) Read(reader io.Reader) error

func (*ProfileTextures) Serialize

func (t *ProfileTextures) Serialize() ([]byte, error)

type Status

type Status struct {
	Brand          string
	Version        string
	VersionFull    string
	CommitHash     string
	BuildTimestamp time.Time
}

represents status information exposed by the server

Jump to

Keyboard shortcuts

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