Package matching

import "github.com/Diarkis/diarkis/matching"

Overview ▾

Package matching ▷

Match Maker - Distributed in-memory match making

Highly scalable and extremely fast match-making based on application defined match making conditions.


Match Maker configurations are explained below.

  "distributionRate": 30,
  "targetNodeType": "HTTP"

▶︎ Configuration Value

distributionRate - Default is 30

Ratio of sharded data saturation among the HTTP server nodes in per centage: e.i. 30 means 30%.

Node type to use for matchmaking - Default is HTTP

func Add

func Add(matchingID string, uniqueID string, tag string, props map[string]int, value map[string]interface{}, ttl int64, limit int)

Add Adds a searchable matching candidate data

matchingID - Pre-defined matching ID that is associated with the matching definition by Define()
uniqueID   - A unique ID for the match making candidate data to prevent duplicates
props      - Match making conditions
value      - Candidate data to be returned when search finds this candidate
ttl        - Defines how long the candidate should be available for search: This is in seconds maximum TTL is 60 seconds
limit      - Defines how many mesh node it should distribute at a time

In order to have long lasting (TTL longer than 60 seconds) searable items, the application must "add" searchable items repeatedly with TTL=60.

matchingID string - Matching profile ID to add the searchable data to.

unqiueID string - Unique ID of the searchable ID.

tag string - Tag is used to isolate and group add and search of matchmaking. If an empty string is given, it will be ignored.

props map[string]int - Searchable condition properties.

value map[string]interface{} - Searchable data to be returned along with the search resilts.

ttl int64 - TTL of the searchable item to be added in seconds. Maximum 60 seconds.

limit int - Number of search node to propagate the searchable item data at a time.

func ClearDefinition

func ClearDefinition(matchingID string)

Clear Definition clears already defined match making definition

matchingID string - Matching profile ID to clear the definition.

func Define

func Define(matchingID string, props map[string]int)

Define Defines a match making search schema: This must be defined on HTTP server b/c all match making data is stored on HTTP servers. You may define as many matching definition as you require as long as each matchingID is unique.

matchingID string - Unique matching profile ID.

props map[string]int - Matching profile condition properties.

func DefineByJSON

func DefineByJSON(jsonBytes []byte)

DefineByJSON defines multiple match making definitions from JSON string.

    "<matching ID>": {
                        "<property name>": <property range value>
                        "<property name>": <property range value>
                        "<property name>": <property range value>

	jsonBytes []byte - Matching profile byte array data to be used to define the profile.

func ExposeCommands

func ExposeCommands()

func Remove

func Remove(matchingID string, uniqueIDList []string, limit int)

Remove removes a list of searchable matching candidate items by their unique IDs NOTE: this function is very expensive as it will send a message to all related mesh nodes

matchingID   - Target matching profile ID to remove items from
uniqueIDList - A list of unique IDs of the searchable items to remove
limit        - Mesh network relay limit
func Search(searchIDList []string, tag string, props map[string]int, limit int, callback func(error, []interface{}))

Search Searchs for matched data based on the given props' values

searchIDList - a list of matchingID to search by. The order of the list is the order of search attempts
tag          - a tag is used to isolate and group search meaning the search will not include tags that do not match.
props        - a property map to act as match making conditions
limit        - a hard limit to the number of results
callback     - a callback with the search results or an error

func SetCustomJoinCondition

func SetCustomJoinCondition(callback func(string, *user.User) bool)

SetCustomJoinCondition assigns a on join evaluation callback to be called to evaluate if the user should join or not

func Setup

func Setup(confpath string)

Setup sets up MatchMaker on the server.

confpath string - Absolute path of the configuration file to be loaded.

func Test

func Test(method string, data map[string]interface{}) ([]byte, error)

Test this is used ONLY in tests