60 | This server is licensed under AGPLv3. The source code can be found on github.
61 | This product includes GeoLite2 data created by MaxMind.
62 |
63 |
64 |
65 |
66 |
--------------------------------------------------------------------------------
/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "flag"
5 | "fmt"
6 | "time"
7 |
8 | "github.com/jinzhu/gorm"
9 | "github.com/labstack/echo/v4"
10 | "github.com/labstack/echo/v4/middleware"
11 | "github.com/labstack/gommon/log"
12 | "github.com/spf13/viper"
13 |
14 | "github.com/libretro/netplay-lobby-server-go/controller"
15 | "github.com/libretro/netplay-lobby-server-go/domain"
16 | "github.com/libretro/netplay-lobby-server-go/model"
17 | "github.com/libretro/netplay-lobby-server-go/model/entity"
18 | "github.com/libretro/netplay-lobby-server-go/model/repository"
19 | )
20 |
21 | func main() {
22 | var verbose = flag.Bool("v", false, "verbose logging")
23 | flag.Parse()
24 |
25 | server := echo.New()
26 | server.HideBanner = true
27 | server.Server.ReadTimeout = 5 * time.Second
28 | server.Server.WriteTimeout = 5 * time.Second
29 |
30 | config, err := readConfig()
31 | if err != nil {
32 | server.Logger.Fatalf("Can't get configuration values: %v", err)
33 | }
34 |
35 | // Init domain logic and model
36 | db, err := initDatabase(config.Database.Type, config.Database.Connection)
37 | if err != nil {
38 | server.Logger.Fatalf("Can't initialize database: %v", err)
39 | }
40 | db = db.AutoMigrate(&entity.Session{})
41 |
42 | if *verbose {
43 | server.Logger.SetLevel(log.INFO)
44 | } else {
45 | server.Logger.SetLevel(log.WARN)
46 | }
47 |
48 | sessionDomain, err := initDomain(db, config)
49 | if err != nil {
50 | server.Logger.Fatalf("Can't initialize domain logic: %v", err)
51 | }
52 |
53 | sessionCotroller := controller.NewSessionController(sessionDomain)
54 |
55 | // Start the cleanup job to purge old sessions
56 | go func() {
57 | for true {
58 | err := sessionDomain.PurgeOld()
59 | if err != nil {
60 | server.Logger.Fatalf("Can't purge old sessions: %v", err)
61 | }
62 | time.Sleep(2 * time.Minute)
63 | }
64 | }()
65 |
66 | // Server setup
67 | server.Use(middleware.Logger())
68 | server.Use(middleware.Recover())
69 | server.Use(middleware.BodyLimit("64K"))
70 |
71 | // Set the routes and prerender templates
72 | sessionCotroller.RegisterRoutes(server)
73 | templatePath := fmt.Sprintf("%s/*.html", config.Server.TemplatePath)
74 | if err = sessionCotroller.PrerenderTemplates(server, templatePath); err != nil {
75 | server.Logger.Fatalf("Can't prerender templates: %v", err)
76 | }
77 |
78 | // Start serving
79 | server.Logger.Fatal(server.Start(config.Server.Address))
80 | }
81 |
82 | func readConfig() (*Config, error) {
83 | viper := viper.New()
84 | viper.SetConfigName("lobby")
85 | viper.SetConfigType("yaml")
86 | viper.AddConfigPath("/etc/lobby")
87 | viper.AddConfigPath("$HOME/.lobby")
88 | viper.AddConfigPath("./config")
89 | if err := viper.ReadInConfig(); err != nil {
90 | return nil, fmt.Errorf("Can't read configuration file: %w", err)
91 | }
92 | var conf Config
93 | if err := viper.Unmarshal(&conf); err != nil {
94 | return nil, fmt.Errorf("Can't unmarshal configuration file: %w", err)
95 | }
96 | return &conf, nil
97 | }
98 |
99 | func initDatabase(databaseType string, connectionString string) (*gorm.DB, error) {
100 | switch databaseType {
101 | case "mysql":
102 | return model.GetMysqlDB(connectionString)
103 | case "postgres":
104 | return model.GetPostgreDB(connectionString)
105 | case "sqlite":
106 | return model.GetSqliteDB(connectionString)
107 | }
108 |
109 | return nil, fmt.Errorf("Unknown database type in configuration: %s", databaseType)
110 | }
111 |
112 | func initDomain(db *gorm.DB, config *Config) (*domain.SessionDomain, error) {
113 | repo := repository.NewSessionRepository(db)
114 | geo2Domain, err := domain.NewGeoIP2Domain(config.Server.GeoLite2Path)
115 | if err != nil {
116 | return nil, fmt.Errorf("Can't intialize geolite2 database: %w", err)
117 | }
118 | validationDomain, err := domain.NewValidationDomain(config.Blacklist.Strings, config.Blacklist.IPs)
119 | if err != nil {
120 | return nil, fmt.Errorf("Can't intialize validation domain: %w", err)
121 | }
122 | mitmDomain := domain.NewMitmDomain(config.Relay)
123 | sessionDomain := domain.NewSessionDomain(repo, geo2Domain, validationDomain, mitmDomain)
124 |
125 | return sessionDomain, nil
126 | }
127 |
--------------------------------------------------------------------------------
/model/entity/session.go:
--------------------------------------------------------------------------------
1 | package entity
2 |
3 | import (
4 | "encoding/hex"
5 | "fmt"
6 | "net"
7 | "strconv"
8 | "strings"
9 | "time"
10 |
11 | "golang.org/x/crypto/sha3"
12 | )
13 |
14 | // HostMethod is the enum for the hosting method.
15 | type HostMethod int64
16 |
17 | // The enum values for HostMethod.
18 | const (
19 | HostMethodUnknown = 0
20 | HostMethodManual = 1
21 | HostMethodUPNP = 2
22 | HostMethodMITM = 3
23 | )
24 |
25 | // Session is the database presentation of a netplay session.
26 | type Session struct {
27 | ID string `json:"-" gorm:"primary_key;size:64"`
28 | ContentHash string `json:"-" gorm:"size:64"`
29 | RoomID int32 `json:"id" gorm:"AUTO_INCREMENT;unique_index"`
30 | Username string `json:"username"`
31 | Country string `json:"country" gorm:"size:2"`
32 | GameName string `json:"game_name"`
33 | GameCRC string `json:"game_crc"`
34 | CoreName string `json:"core_name"`
35 | CoreVersion string `json:"core_version"`
36 | SubsystemName string `json:"subsystem_name"`
37 | RetroArchVersion string `json:"retroarch_version"`
38 | Frontend string `json:"frontend"`
39 | IP net.IP `json:"ip" gorm:"not null"`
40 | Port uint16 `json:"port"`
41 | MitmHandle string `json:"-"`
42 | MitmAddress string `json:"mitm_ip"`
43 | MitmPort uint16 `json:"mitm_port"`
44 | MitmSession string `json:"mitm_session"`
45 | HostMethod HostMethod `json:"host_method"`
46 | HasPassword bool `json:"has_password"`
47 | HasSpectatePassword bool `json:"has_spectate_password"`
48 | Connectable bool `json:"connectable"`
49 | IsRetroArch bool `json:"is_retroarch"`
50 | PlayerCount int16 `json:"player_count"`
51 | SpectatorCount int16 `json:"spectator_count"`
52 | CreatedAt time.Time `json:"created"`
53 | UpdatedAt time.Time `json:"updated" gorm:"index"`
54 | }
55 |
56 | // CalculateID creates a 32 byte SHAKE256 (SHA3) hash of the session for the db to use as PK.
57 | func (s *Session) CalculateID() {
58 | hash := make([]byte, 32)
59 | shake := sha3.NewShake256()
60 |
61 | shake.Write([]byte(s.Username))
62 | shake.Write([]byte(s.IP))
63 | shake.Write([]byte(strconv.FormatUint(uint64(s.Port), 10)))
64 |
65 | shake.Read(hash)
66 |
67 | s.ID = hex.EncodeToString(hash)
68 | }
69 |
70 | // CalculateContentHash creates a 32 byte SHAKE256 (SHA3) hash of the session content.
71 | func (s *Session) CalculateContentHash() {
72 | hash := make([]byte, 32)
73 | shake := sha3.NewShake256()
74 |
75 | shake.Write([]byte(s.Username))
76 | shake.Write([]byte(s.GameName))
77 | shake.Write([]byte(s.GameCRC))
78 | shake.Write([]byte(s.CoreName))
79 | shake.Write([]byte(s.CoreVersion))
80 | shake.Write([]byte(s.SubsystemName))
81 | shake.Write([]byte(s.RetroArchVersion))
82 | shake.Write([]byte(s.Frontend))
83 | shake.Write([]byte(s.IP))
84 | shake.Write([]byte(strconv.FormatUint(uint64(s.Port), 10)))
85 | shake.Write([]byte(strconv.FormatUint(uint64(s.HostMethod), 10)))
86 | shake.Write([]byte(s.MitmHandle))
87 | shake.Write([]byte(s.MitmSession))
88 | shake.Write([]byte(strconv.FormatBool(s.HasPassword)))
89 | shake.Write([]byte(strconv.FormatBool(s.HasSpectatePassword)))
90 |
91 | shake.Read(hash)
92 |
93 | s.ContentHash = hex.EncodeToString(hash)
94 | }
95 |
96 | // PrintForRetroarch prints out the session information in a format that retroarch is expecting.
97 | func (s *Session) PrintForRetroarch() string {
98 | var str string
99 | var hasPassword = 0
100 | var hasSpectatePassword = 0
101 | var connectable = 0
102 |
103 | if s.HasPassword {
104 | hasPassword = 1
105 | }
106 |
107 | if s.HasSpectatePassword {
108 | hasSpectatePassword = 1
109 | }
110 |
111 | if s.Connectable {
112 | connectable = 1
113 | }
114 |
115 | str += fmt.Sprintf("id=%d\nusername=%s\ncore_name=%s\ngame_name=%s\ngame_crc=%s\ncore_version=%s\nip=%s\nport=%d\nhost_method=%d\nhas_password=%d\nhas_spectate_password=%d\nretroarch_version=%s\nfrontend=%s\nsubsystem_name=%s\ncountry=%s\nconnectable=%d\n",
116 | s.RoomID,
117 | s.Username,
118 | s.CoreName,
119 | s.GameName,
120 | strings.ToUpper(s.GameCRC),
121 | s.CoreVersion,
122 | s.IP,
123 | s.Port,
124 | s.HostMethod,
125 | hasPassword,
126 | hasSpectatePassword,
127 | s.RetroArchVersion,
128 | s.Frontend,
129 | s.SubsystemName,
130 | strings.ToUpper(s.Country),
131 | connectable,
132 | )
133 |
134 | return str
135 | }
136 |
--------------------------------------------------------------------------------
/controller/sessioncontroller.go:
--------------------------------------------------------------------------------
1 | package controller
2 |
3 | import (
4 | "errors"
5 | "fmt"
6 | "html/template"
7 | "io"
8 | "net"
9 | "net/http"
10 | "strconv"
11 | "time"
12 |
13 | "github.com/labstack/echo/v4"
14 | "github.com/libretro/netplay-lobby-server-go/domain"
15 | "github.com/libretro/netplay-lobby-server-go/model/entity"
16 | )
17 |
18 | // Template abspracts the template rendering.
19 | type Template struct {
20 | templates *template.Template
21 | }
22 |
23 | // Render implements the echo template rendering interface
24 | func (t *Template) Render(w io.Writer, name string, data interface{}, c echo.Context) error {
25 | return t.templates.ExecuteTemplate(w, name, data)
26 | }
27 |
28 | // SessionDomain interface to decouple the controller logic from the domain code.
29 | type SessionDomain interface {
30 | Add(request *domain.AddSessionRequest, ip net.IP) (*entity.Session, error)
31 | Get(roomID int32) (*entity.Session, error)
32 | List() ([]entity.Session, error)
33 | GetMitm() *domain.MitmDomain
34 | PurgeOld() error
35 | }
36 |
37 | // ListSessionsResponse is a custom DTO for backward compatability.
38 | type SessionsResponse struct {
39 | Fields entity.Session `json:"fields"`
40 | }
41 |
42 | // SessionController handles all session related request
43 | type SessionController struct {
44 | sessionDomain SessionDomain
45 | }
46 |
47 | // NewSessionController returns a new session controller
48 | func NewSessionController(sessionDomain SessionDomain) *SessionController {
49 | return &SessionController{sessionDomain}
50 | }
51 |
52 | // RegisterRoutes registers all controller routes at an echo framework instance.
53 | func (c *SessionController) RegisterRoutes(server *echo.Echo) {
54 | server.POST("/add", c.Add)
55 | server.POST("/add/", c.Add) // Legacy path
56 | server.GET("/list", c.List)
57 | server.GET("/list/", c.List) // Legacy path
58 | server.GET("/tunnel", c.Tunnel)
59 | server.GET("/tunnel/", c.Tunnel) // Legacy path
60 | server.GET("/", c.Index)
61 | server.GET("/:roomID", c.Get)
62 | server.GET("/:roomID/", c.Get) // Legacy path
63 | }
64 |
65 | // PrerenderTemplates prerenders all templates
66 | func (c *SessionController) PrerenderTemplates(server *echo.Echo, filePattern string) error {
67 | templates, err := template.New("").Funcs(
68 | template.FuncMap{
69 | "prettyBool": func(b bool) string {
70 | if b {
71 | return "Yes"
72 | }
73 | return "No"
74 | },
75 | "prettyDate": func(d time.Time) string {
76 | utc, _ := time.LoadLocation("UTC")
77 | return d.In(utc).Format(time.RFC822)
78 | },
79 | },
80 | ).ParseGlob(filePattern)
81 |
82 | if err != nil {
83 | return fmt.Errorf("Can't parse template: %w", err)
84 | }
85 |
86 | t := &Template{
87 | templates: templates,
88 | }
89 | server.Renderer = t
90 | return nil
91 | }
92 |
93 | // Index handler
94 | // GET /
95 | func (c *SessionController) Index(ctx echo.Context) error {
96 | logger := ctx.Logger()
97 |
98 | sessions, err := c.sessionDomain.List()
99 | if err != nil {
100 | logger.Errorf("Can't render session list: %v", err)
101 | return ctx.NoContent(http.StatusInternalServerError)
102 | }
103 |
104 | return ctx.Render(http.StatusOK, "index.html", sessions)
105 | }
106 |
107 | // Get handler
108 | // GET /:roomID
109 | func (c *SessionController) Get(ctx echo.Context) error {
110 | logger := ctx.Logger()
111 |
112 | roomIDString := ctx.Param("roomID")
113 | roomID, err := strconv.ParseInt(roomIDString, 10, 32)
114 | if err != nil {
115 | logger.Errorf("Can't get session by roomID. The RoomID wasn't a valid int32: %v", err)
116 | return ctx.NoContent(http.StatusBadRequest)
117 | }
118 |
119 | session, err := c.sessionDomain.Get(int32(roomID))
120 | if err != nil || session == nil {
121 | logger.Errorf("Can't get session: %v", err)
122 | return ctx.NoContent(http.StatusNotFound)
123 | }
124 |
125 | // For legacy reasons, we need to put the sessions inside a wrapper object
126 | // that has the session accessible under the key "fields". The old implementation
127 | // also returned a list for one entry...
128 | response := make([]SessionsResponse, 1)
129 | response[0] = SessionsResponse{*session}
130 | return ctx.JSONPretty(http.StatusOK, response, " ")
131 | }
132 |
133 | // List handler
134 | // GET /list
135 | func (c *SessionController) List(ctx echo.Context) error {
136 | logger := ctx.Logger()
137 |
138 | sessions, err := c.sessionDomain.List()
139 | if err != nil {
140 | logger.Errorf("Can't render session list: %v", err)
141 | return ctx.NoContent(http.StatusInternalServerError)
142 | }
143 |
144 | // For legacy reasons, we need to put the sessions inside a wrapper object
145 | // that has the session accessible under the key "fields"
146 | response := make([]SessionsResponse, len(sessions))
147 | for i, session := range sessions {
148 | response[i].Fields = session
149 | }
150 |
151 | return ctx.JSONPretty(http.StatusOK, response, " ")
152 | }
153 |
154 | // Add handler
155 | // POST /add
156 | func (c *SessionController) Add(ctx echo.Context) error {
157 | logger := ctx.Logger()
158 | var err error
159 | var session *entity.Session
160 |
161 | var req domain.AddSessionRequest
162 | if err := ctx.Bind(&req); err != nil {
163 | logger.Errorf("Can't parse incomming session: %v", err)
164 | return ctx.NoContent(http.StatusBadRequest)
165 | }
166 |
167 | ip := net.ParseIP(ctx.RealIP())
168 |
169 | if session, err = c.sessionDomain.Add(&req, ip); err != nil {
170 | logger.Errorf("Won't add session: %v", err)
171 |
172 | if errors.Is(err, domain.ErrSessionRejected) {
173 | logger.Errorf("Rejected session: %v", session)
174 | return ctx.NoContent(http.StatusBadRequest)
175 | } else if errors.Is(err, domain.ErrRateLimited) {
176 | return ctx.NoContent(http.StatusTooManyRequests)
177 | }
178 | return ctx.NoContent(http.StatusBadRequest)
179 | }
180 |
181 | result := "status=OK\n"
182 | result += session.PrintForRetroarch()
183 | return ctx.String(http.StatusOK, result)
184 | }
185 |
186 | // Tunnel handler
187 | // GET /tunnel
188 | func (c *SessionController) Tunnel(ctx echo.Context) error {
189 | logger := ctx.Logger()
190 |
191 | tunnelName := ctx.QueryParam("name")
192 | if tunnelName == "" {
193 | return ctx.NoContent(http.StatusBadRequest)
194 | }
195 |
196 | tunnel := c.sessionDomain.GetMitm().GetInfo(tunnelName)
197 | if tunnel == nil {
198 | logger.Errorf("Can't find tunnel server: '%s'", tunnelName)
199 | return ctx.NoContent(http.StatusNotFound)
200 | }
201 |
202 | result := "status=OK\n"
203 | result += tunnel.PrintForRetroarch()
204 | return ctx.String(http.StatusOK, result)
205 | }
206 |
--------------------------------------------------------------------------------
/controller/sessioncontroller_test.go:
--------------------------------------------------------------------------------
1 | package controller
2 |
3 | import (
4 | "errors"
5 | "net"
6 | "net/http"
7 | "net/http/httptest"
8 | "testing"
9 | "time"
10 |
11 | "github.com/labstack/echo/v4"
12 | "github.com/stretchr/testify/assert"
13 | "github.com/stretchr/testify/mock"
14 | "github.com/stretchr/testify/require"
15 |
16 | "github.com/libretro/netplay-lobby-server-go/domain"
17 | "github.com/libretro/netplay-lobby-server-go/model/entity"
18 | )
19 |
20 | var testSession = entity.Session{
21 | ID: "",
22 | RoomID: 0,
23 | Username: "zelda",
24 | Country: "en",
25 | GameName: "supergame",
26 | GameCRC: "FFFFFFFF",
27 | CoreName: "unes",
28 | CoreVersion: "0.2.1",
29 | SubsystemName: "subsub",
30 | RetroArchVersion: "1.1.1",
31 | Frontend: "retro",
32 | IP: net.ParseIP("127.0.0.1"),
33 | Port: 55355,
34 | MitmAddress: "",
35 | MitmPort: 0,
36 | MitmSession: "",
37 | HostMethod: entity.HostMethodUPNP,
38 | HasPassword: false,
39 | HasSpectatePassword: false,
40 | Connectable: true,
41 | IsRetroArch: true,
42 | CreatedAt: time.Date(2010, 9, 12, 11, 33, 05, 0, time.UTC),
43 | UpdatedAt: time.Date(2010, 9, 12, 11, 33, 05, 0, time.UTC),
44 | ContentHash: "",
45 | }
46 |
47 | type SessionDomainMock struct {
48 | mock.Mock
49 | }
50 |
51 | func (m *SessionDomainMock) Add(request *domain.AddSessionRequest, ip net.IP) (*entity.Session, error) {
52 | args := m.Called(request, ip)
53 | session, _ := args.Get(0).(*entity.Session)
54 | return session, args.Error(1)
55 | }
56 |
57 | func (m *SessionDomainMock) Get(roomID int32) (*entity.Session, error) {
58 | args := m.Called(roomID)
59 | session, _ := args.Get(0).(*entity.Session)
60 | return session, args.Error(1)
61 | }
62 |
63 | func (m *SessionDomainMock) List() ([]entity.Session, error) {
64 | args := m.Called()
65 | sessions, _ := args.Get(0).([]entity.Session)
66 | return sessions, args.Error(1)
67 | }
68 |
69 | func (m *SessionDomainMock) PurgeOld() error {
70 | args := m.Called()
71 | return args.Error(0)
72 | }
73 |
74 | func (d *SessionDomainMock) GetMitm() *domain.MitmDomain {
75 | return nil
76 | }
77 |
78 | func TestSessionControllerIndex(t *testing.T) {
79 | domainMock := &SessionDomainMock{}
80 |
81 | server := echo.New()
82 | req := httptest.NewRequest(http.MethodGet, "/", nil)
83 | rec := httptest.NewRecorder()
84 | ctx := server.NewContext(req, rec)
85 | handler := NewSessionController(domainMock)
86 | err := handler.PrerenderTemplates(server, "../web/templates/*.html")
87 | require.NoError(t, err)
88 |
89 | session1 := testSession
90 | session1.Username = "Player 1"
91 | session2 := testSession
92 | session2.Username = "Player 2"
93 | sessions := []entity.Session{session1, session2}
94 | domainMock.On("List").Return(sessions, nil)
95 |
96 | handler.Index(ctx)
97 |
98 | assert.Equal(t, http.StatusOK, rec.Code)
99 | assert.Contains(t, rec.Body.String(), "Player 1")
100 | assert.Contains(t, rec.Body.String(), "Player 2")
101 | }
102 |
103 | func TestSessionControllerGet(t *testing.T) {
104 | domainMock := &SessionDomainMock{}
105 |
106 | server := echo.New()
107 | req := httptest.NewRequest(http.MethodGet, "/", nil)
108 | rec := httptest.NewRecorder()
109 | ctx := server.NewContext(req, rec)
110 | ctx.SetPath("/:roomID")
111 | ctx.SetParamNames("roomID")
112 | ctx.SetParamValues("100")
113 | handler := NewSessionController(domainMock)
114 |
115 | session := testSession
116 | expectedResultBody := `[
117 | {
118 | "fields": {
119 | "id": 0,
120 | "username": "zelda",
121 | "country": "en",
122 | "game_name": "supergame",
123 | "game_crc": "FFFFFFFF",
124 | "core_name": "unes",
125 | "core_version": "0.2.1",
126 | "subsystem_name": "subsub",
127 | "retroarch_version": "1.1.1",
128 | "frontend": "retro",
129 | "ip": "127.0.0.1",
130 | "port": 55355,
131 | "mitm_ip": "",
132 | "mitm_port": 0,
133 | "mitm_session": "",
134 | "host_method": 2,
135 | "has_password": false,
136 | "has_spectate_password": false,
137 | "connectable": true,
138 | "is_retroarch": true,
139 | "player_count": 0,
140 | "spectator_count": 0,
141 | "created": "2010-09-12T11:33:05Z",
142 | "updated": "2010-09-12T11:33:05Z"
143 | }
144 | }
145 | ]
146 | `
147 | domainMock.On("Get", int32(100)).Return(&session, nil)
148 |
149 | handler.Get(ctx)
150 | assert.Equal(t, http.StatusOK, rec.Code)
151 | assert.Equal(t, expectedResultBody, rec.Body.String())
152 | }
153 |
154 | func TestSessionControllerList(t *testing.T) {
155 | domainMock := &SessionDomainMock{}
156 |
157 | server := echo.New()
158 | req := httptest.NewRequest(http.MethodGet, "/list", nil)
159 | rec := httptest.NewRecorder()
160 | ctx := server.NewContext(req, rec)
161 | handler := NewSessionController(domainMock)
162 |
163 | session := testSession
164 | sessions := []entity.Session{session}
165 | expectedResultBody := `[
166 | {
167 | "fields": {
168 | "id": 0,
169 | "username": "zelda",
170 | "country": "en",
171 | "game_name": "supergame",
172 | "game_crc": "FFFFFFFF",
173 | "core_name": "unes",
174 | "core_version": "0.2.1",
175 | "subsystem_name": "subsub",
176 | "retroarch_version": "1.1.1",
177 | "frontend": "retro",
178 | "ip": "127.0.0.1",
179 | "port": 55355,
180 | "mitm_ip": "",
181 | "mitm_port": 0,
182 | "mitm_session": "",
183 | "host_method": 2,
184 | "has_password": false,
185 | "has_spectate_password": false,
186 | "connectable": true,
187 | "is_retroarch": true,
188 | "player_count": 0,
189 | "spectator_count": 0,
190 | "created": "2010-09-12T11:33:05Z",
191 | "updated": "2010-09-12T11:33:05Z"
192 | }
193 | }
194 | ]
195 | `
196 | domainMock.On("List").Return(sessions, nil)
197 |
198 | handler.List(ctx)
199 | assert.Equal(t, http.StatusOK, rec.Code)
200 | assert.Equal(t, expectedResultBody, rec.Body.String())
201 | }
202 |
203 | func TestSessionControllerListError(t *testing.T) {
204 | domainMock := &SessionDomainMock{}
205 |
206 | e := echo.New()
207 | req := httptest.NewRequest(http.MethodGet, "/list", nil)
208 | rec := httptest.NewRecorder()
209 | ctx := e.NewContext(req, rec)
210 | handler := NewSessionController(domainMock)
211 |
212 | domainMock.On("List").Return(nil, errors.New("test error"))
213 |
214 | handler.List(ctx)
215 | assert.Equal(t, http.StatusInternalServerError, rec.Code)
216 | assert.Equal(t, "", rec.Body.String())
217 | }
218 |
--------------------------------------------------------------------------------
/model/repository/sessionrepository_test.go:
--------------------------------------------------------------------------------
1 | package repository
2 |
3 | import (
4 | "net"
5 | "testing"
6 | "time"
7 |
8 | "github.com/stretchr/testify/assert"
9 | "github.com/stretchr/testify/require"
10 |
11 | "github.com/libretro/netplay-lobby-server-go/model"
12 | "github.com/libretro/netplay-lobby-server-go/model/entity"
13 | )
14 |
15 | var testSession = entity.Session{
16 | ID: "",
17 | RoomID: 0,
18 | Username: "zelda",
19 | Country: "en",
20 | GameName: "supergame",
21 | GameCRC: "FFFFFFFF",
22 | CoreName: "unes",
23 | CoreVersion: "0.2.1",
24 | SubsystemName: "subsub",
25 | RetroArchVersion: "1.1.1",
26 | Frontend: "retro",
27 | IP: net.ParseIP("127.0.0.1"),
28 | Port: 55355,
29 | MitmAddress: "",
30 | MitmPort: 0,
31 | MitmSession: "",
32 | HostMethod: entity.HostMethodUPNP,
33 | HasPassword: false,
34 | HasSpectatePassword: false,
35 | Connectable: true,
36 | IsRetroArch: true,
37 | PlayerCount: 2,
38 | SpectatorCount: 1,
39 | CreatedAt: time.Now(),
40 | UpdatedAt: time.Now(),
41 | ContentHash: "",
42 | }
43 |
44 | func setupSessionRepository(t *testing.T) *SessionRepository {
45 | db, err := model.GetSqliteDB(":memory:")
46 | //db = db.LogMode(true)
47 | if err != nil {
48 | t.Fatalf("Can't open sqlite3 db: %v", err)
49 | }
50 | db.AutoMigrate(entity.Session{})
51 |
52 | return NewSessionRepository(db)
53 | }
54 |
55 | func TestSessionRepositoryCreate(t *testing.T) {
56 | sessionRepository := setupSessionRepository(t)
57 | session := testSession
58 |
59 | session.CalculateID()
60 | session.CalculateContentHash()
61 | err := sessionRepository.Create(&session)
62 | require.NoError(t, err, "Can't create session")
63 | }
64 |
65 | func TestSessionRepositoryCreateIPNotNull(t *testing.T) {
66 | sessionRepository := setupSessionRepository(t)
67 | session := testSession
68 |
69 | session.IP = nil
70 | session.CalculateID()
71 | session.CalculateContentHash()
72 | err := sessionRepository.Create(&session)
73 | require.Error(t, err, "Should not be able to create nil value for IP")
74 | }
75 |
76 | func TestSessionRepositoryGetByID(t *testing.T) {
77 | sessionRepository := setupSessionRepository(t)
78 | session := testSession
79 |
80 | session.CalculateID()
81 | session.CalculateContentHash()
82 | err := sessionRepository.Create(&session)
83 | require.NoError(t, err, "Can't create session")
84 |
85 | newSession, err := sessionRepository.GetByID(session.ID)
86 | require.NoError(t, err, "Can't get session by ID")
87 |
88 | require.NotNil(t, newSession)
89 |
90 | assert.NotEmpty(t, newSession.ID)
91 | assert.NotEmpty(t, newSession.ContentHash)
92 |
93 | assert.NotEqual(t, session.CreatedAt, newSession.CreatedAt)
94 | assert.NotEqual(t, session.UpdatedAt, newSession.UpdatedAt)
95 |
96 | // Make sure the rest is the same
97 | session.CreatedAt = newSession.CreatedAt
98 | session.UpdatedAt = newSession.UpdatedAt
99 | assert.Equal(t, &session, newSession)
100 |
101 | noSession, err := sessionRepository.GetByID("should_not_exists")
102 | require.NoError(t, err, "Can't get nil session")
103 | assert.Nil(t, noSession)
104 | }
105 |
106 | func TestSessionRepositoryGetByRoomID(t *testing.T) {
107 | sessionRepository := setupSessionRepository(t)
108 | session := testSession
109 |
110 | session.RoomID = 400
111 | session.CalculateID()
112 | session.CalculateContentHash()
113 | err := sessionRepository.Create(&session)
114 | require.NoError(t, err, "Can't create session")
115 |
116 | newSession, err := sessionRepository.GetByRoomID(session.RoomID)
117 | require.NoError(t, err, "Can't get session by RoomID")
118 |
119 | require.NotNil(t, newSession)
120 |
121 | assert.NotEmpty(t, newSession.ID)
122 | assert.NotEmpty(t, newSession.ContentHash)
123 |
124 | assert.NotEqual(t, session.CreatedAt, newSession.CreatedAt)
125 | assert.NotEqual(t, session.UpdatedAt, newSession.UpdatedAt)
126 |
127 | // Make sure the rest is the same
128 | session.CreatedAt = newSession.CreatedAt
129 | session.UpdatedAt = newSession.UpdatedAt
130 | assert.Equal(t, &session, newSession)
131 |
132 | noSession, err := sessionRepository.GetByID("should_not_exists")
133 | require.NoError(t, err, "Can't get nil session")
134 | assert.Nil(t, noSession)
135 | }
136 |
137 | func TestSessionRepositoryGetAll(t *testing.T) {
138 | sessionRepository := setupSessionRepository(t)
139 | session := testSession
140 |
141 | session.CalculateID()
142 | session.CalculateContentHash()
143 | session.RoomID = 0
144 | err := sessionRepository.Create(&session)
145 | require.NoError(t, err, "Can't create session")
146 |
147 | session.Username = "aladin"
148 | session.CalculateID()
149 | session.CalculateContentHash()
150 | session.RoomID = 0
151 | err = sessionRepository.Create(&session)
152 | require.NoError(t, err, "Can't create session")
153 |
154 | session.Username = "invalid"
155 | session.UpdatedAt = time.Now().Add(-2 * time.Minute)
156 | session.CalculateID()
157 | session.CalculateContentHash()
158 | session.RoomID = 0
159 | err = sessionRepository.Create(&session)
160 | require.NoError(t, err, "Can't create session")
161 |
162 | deadline := time.Now().Add(-1 * time.Minute)
163 | sessions, err := sessionRepository.GetAll(deadline)
164 | require.NoError(t, err, "Can't get all sessions with deadline")
165 |
166 | require.NotNil(t, sessions)
167 | require.Equal(t, 2, len(sessions), "Query seems to include non valid entries.")
168 | assert.Less(t, sessions[0].Username, sessions[1].Username, "Sessions are not ordered by username")
169 |
170 | sessions, err = sessionRepository.GetAll(time.Time{})
171 | require.NoError(t, err, "Can't get all sessions without deadline")
172 |
173 | require.NotNil(t, sessions)
174 | require.Equal(t, 3, len(sessions), "Query seems to not include invalid entries.")
175 | assert.Less(t, sessions[0].Username, sessions[1].Username, "Sessions are not ordered by username")
176 | assert.Less(t, sessions[1].Username, sessions[2].Username, "Sessions are not ordered by username")
177 | }
178 |
179 | func TestSessionRepositoryUpdate(t *testing.T) {
180 | sessionRepository := setupSessionRepository(t)
181 | session := testSession
182 |
183 | session.CalculateID()
184 | session.CalculateContentHash()
185 | err := sessionRepository.Create(&session)
186 | require.NoError(t, err, "Can't create session")
187 |
188 | newIP := "83.12.41.222"
189 | session.MitmAddress = newIP
190 |
191 | session.CalculateContentHash()
192 | err = sessionRepository.Update(&session)
193 | require.NoError(t, err, "Can't update session")
194 |
195 | newSession, err := sessionRepository.GetByID(session.ID)
196 | require.NoError(t, err, "Can't get session by ID")
197 |
198 | require.NotNil(t, newSession)
199 | assert.Equal(t, newSession.MitmAddress, newIP)
200 | }
201 |
202 | func TestSessionRepositoryTouch(t *testing.T) {
203 | sessionRepository := setupSessionRepository(t)
204 | session := testSession
205 |
206 | session.CalculateID()
207 | session.CalculateContentHash()
208 | err := sessionRepository.Create(&session)
209 | require.NoError(t, err, "Can't create session")
210 |
211 | oldSession, err := sessionRepository.GetByID(session.ID)
212 | require.NoError(t, err, "Can't get session by ID")
213 |
214 | oldTimestamp := oldSession.UpdatedAt
215 |
216 | err = sessionRepository.Touch(oldSession)
217 | require.NoError(t, err, "Can't touch session")
218 |
219 | newSession, err := sessionRepository.GetByID(session.ID)
220 | require.NoError(t, err, "Can't get session by ID")
221 |
222 | require.NotNil(t, newSession)
223 | assert.False(t, newSession.UpdatedAt.Equal(oldTimestamp), "New timestamp did not change after touch")
224 | assert.True(t, newSession.UpdatedAt.After(oldTimestamp), "New timestamp is not older after touch")
225 |
226 | assert.Equal(t, oldSession.ContentHash, newSession.ContentHash)
227 | }
228 |
229 | func TestSessionRepositoryTouchPlayerCount(t *testing.T) {
230 | sessionRepository := setupSessionRepository(t)
231 | session1 := testSession
232 | session2 := testSession
233 | session2.PlayerCount = 3
234 |
235 | session1.CalculateID()
236 | session1.CalculateContentHash()
237 | err := sessionRepository.Create(&session1)
238 | require.NoError(t, err, "Can't create session")
239 |
240 | prevSession, err := sessionRepository.GetByID(session1.ID)
241 | require.NoError(t, err, "Can't get session by ID")
242 |
243 | session2.CalculateID()
244 | session2.CalculateContentHash()
245 | err = sessionRepository.Touch(&session2)
246 | require.NoError(t, err, "Can't touch session")
247 |
248 | newSession, err := sessionRepository.GetByID(session1.ID)
249 | require.NoError(t, err, "Can't get session by ID")
250 |
251 | require.NotNil(t, newSession)
252 |
253 | assert.Equal(t, prevSession.ContentHash, newSession.ContentHash)
254 | assert.NotEqual(t, prevSession.PlayerCount, newSession.PlayerCount)
255 | }
256 |
257 | func TestSessionRepositoryPurgeOld(t *testing.T) {
258 | sessionRepository := setupSessionRepository(t)
259 | session := testSession
260 |
261 | session.CalculateID()
262 | session.CalculateContentHash()
263 | session.RoomID = 0
264 | err := sessionRepository.Create(&session)
265 | require.NoError(t, err, "Can't create session")
266 |
267 | session.Username = "aladin"
268 | session.CalculateID()
269 | session.CalculateContentHash()
270 | session.RoomID = 0
271 | err = sessionRepository.Create(&session)
272 | require.NoError(t, err, "Can't create session")
273 |
274 | session.Username = "invalid"
275 | session.UpdatedAt = time.Now().Add(-2 * time.Minute)
276 | session.CalculateID()
277 | session.CalculateContentHash()
278 | session.RoomID = 0
279 | err = sessionRepository.Create(&session)
280 | require.NoError(t, err, "Can't create session")
281 |
282 | deadline := time.Now().Add(-1 * time.Minute)
283 | err = sessionRepository.PurgeOld(deadline)
284 | require.NoError(t, err, "Can't purge old sessions")
285 |
286 | sessions, err := sessionRepository.GetAll(time.Time{})
287 | require.NoError(t, err, "Can't get all sessions")
288 |
289 | require.NotNil(t, sessions)
290 | require.Equal(t, len(sessions), 2, "Query seems to include non valid entries.")
291 | }
292 |
--------------------------------------------------------------------------------
/domain/sessiondomain_test.go:
--------------------------------------------------------------------------------
1 | package domain
2 |
3 | import (
4 | "errors"
5 | "net"
6 | "testing"
7 | "time"
8 |
9 | "github.com/stretchr/testify/assert"
10 | "github.com/stretchr/testify/mock"
11 | "github.com/stretchr/testify/require"
12 |
13 | "github.com/libretro/netplay-lobby-server-go/model/entity"
14 | )
15 |
16 | var testIP = net.ParseIP("192.168.178.2")
17 |
18 | // testRequest and testSession should have the same values for the test below.
19 | var playercnt int16 = 2
20 | var spectacnt int16 = 1
21 |
22 | var testRequest = AddSessionRequest{
23 | Username: "zelda",
24 | CoreName: "bsnes",
25 | CoreVersion: "0.2.1",
26 | GameName: "supergame",
27 | GameCRC: "FFFFFFFF",
28 | Port: 55355,
29 | MITMServer: "",
30 | HasPassword: false,
31 | HasSpectatePassword: false,
32 | ForceMITM: false,
33 | RetroArchVersion: "1.1.1",
34 | Frontend: "retro",
35 | SubsystemName: "subsub",
36 | MITMSession: "",
37 | MITMCustomServer: "",
38 | MITMCustomPort: 0,
39 | PlayerCount: &playercnt,
40 | SpectatorCount: &spectacnt,
41 | }
42 |
43 | var testSession = entity.Session{
44 | ID: "",
45 | RoomID: 100,
46 | Username: "zelda",
47 | Country: "en",
48 | GameName: "supergame",
49 | GameCRC: "FFFFFFFF",
50 | CoreName: "bsnes",
51 | CoreVersion: "0.2.1",
52 | SubsystemName: "subsub",
53 | RetroArchVersion: "1.1.1",
54 | Frontend: "retro",
55 | IP: net.ParseIP("192.168.178.2"),
56 | Port: 55355,
57 | MitmHandle: "",
58 | MitmAddress: "",
59 | MitmPort: 0,
60 | MitmSession: "",
61 | HostMethod: entity.HostMethodUnknown,
62 | HasPassword: false,
63 | HasSpectatePassword: false,
64 | Connectable: true,
65 | IsRetroArch: true,
66 | PlayerCount: 2,
67 | SpectatorCount: 1,
68 | CreatedAt: time.Now().Add(-5 * time.Minute),
69 | UpdatedAt: time.Now().Add(-5 * time.Minute),
70 | ContentHash: "",
71 | }
72 |
73 | type SessionRepositoryMock struct {
74 | mock.Mock
75 | }
76 |
77 | func (m *SessionRepositoryMock) Create(s *entity.Session) error {
78 | args := m.Called(s)
79 | return args.Error(0)
80 | }
81 |
82 | func (m *SessionRepositoryMock) Update(s *entity.Session) error {
83 | args := m.Called(s)
84 | return args.Error(0)
85 | }
86 |
87 | func (m *SessionRepositoryMock) Touch(s *entity.Session) error {
88 | args := m.Called(s.ID)
89 | return args.Error(0)
90 | }
91 |
92 | func (m *SessionRepositoryMock) GetByID(id string) (*entity.Session, error) {
93 | args := m.Called(id)
94 | session, _ := args.Get(0).(*entity.Session)
95 | return session, args.Error(1)
96 | }
97 |
98 | func (m *SessionRepositoryMock) GetByRoomID(roomID int32) (*entity.Session, error) {
99 | args := m.Called(roomID)
100 | session, _ := args.Get(0).(*entity.Session)
101 | return session, args.Error(1)
102 | }
103 |
104 | func (m *SessionRepositoryMock) GetAll(deadline time.Time) ([]entity.Session, error) {
105 | args := m.Called(deadline)
106 | sessions, _ := args.Get(0).([]entity.Session)
107 | return sessions, args.Error(1)
108 | }
109 |
110 | func (m *SessionRepositoryMock) PurgeOld(deadline time.Time) error {
111 | args := m.Called(deadline)
112 | return args.Error(0)
113 | }
114 |
115 | func setupSessionDomain(t *testing.T) (*SessionDomain, *SessionRepositoryMock) {
116 | repoMock := SessionRepositoryMock{}
117 |
118 | validationDomain, err := NewValidationDomain(testStringBlacklist, testIPBlacklist)
119 | require.NoError(t, err)
120 |
121 | geoip2Domain := setupGeoip2Domain(t)
122 |
123 | sessionDomain := NewSessionDomain(&repoMock, geoip2Domain, validationDomain, &MitmDomain{})
124 | require.NoError(t, err)
125 |
126 | return sessionDomain, &repoMock
127 | }
128 |
129 | func TestSessionDomainPurgeOld(t *testing.T) {
130 | sessionDomain, repoMock := setupSessionDomain(t)
131 |
132 | // Test the deadline duration
133 | repoMock.On("PurgeOld", mock.MatchedBy(
134 | func(d time.Time) bool {
135 | before := time.Now().Add(-(SessionDeadline - 1) * time.Second)
136 | after := time.Now().Add(-(SessionDeadline + 1) * time.Second)
137 | return d.Before(before) && d.After(after)
138 | })).Return(nil)
139 |
140 | err := sessionDomain.PurgeOld()
141 | require.NoError(t, err, "Can't purge old sessions")
142 | }
143 |
144 | func TestSessionDomainList(t *testing.T) {
145 | sessionDomain, repoMock := setupSessionDomain(t)
146 |
147 | // Test the deadline duration
148 | repoMock.On("GetAll", mock.MatchedBy(
149 | func(d time.Time) bool {
150 | before := time.Now().Add(-(SessionDeadline - 1) * time.Second)
151 | after := time.Now().Add(-(SessionDeadline + 1) * time.Second)
152 | return d.Before(before) && d.After(after)
153 | })).Return(make([]entity.Session, 3), nil)
154 |
155 | sessions, err := sessionDomain.List()
156 | require.NoError(t, err, "Can't list sessions")
157 | require.NotNil(t, sessions)
158 | assert.Equal(t, 3, len(sessions))
159 | }
160 |
161 | func TestSessionDomainValidateSessionAtCreate(t *testing.T) {
162 | sessionDomain, repoMock := setupSessionDomain(t)
163 |
164 | request := testRequest
165 | comp := testSession
166 | comp.CalculateID()
167 | comp.CalculateContentHash()
168 |
169 | request.GameCRC = "123456789"
170 |
171 | repoMock.On("GetByID", mock.MatchedBy(
172 | func(s string) bool {
173 | return s == comp.ID
174 | })).Return(nil, nil)
175 |
176 | newSession, err := sessionDomain.Add(&request, testIP)
177 | require.Error(t, err)
178 | assert.Nil(t, newSession)
179 | assert.True(t, errors.Is(err, ErrSessionRejected))
180 | }
181 |
182 | func TestSessionDomainValidateSessionAtUpdate(t *testing.T) {
183 | sessionDomain, repoMock := setupSessionDomain(t)
184 |
185 | request := testRequest
186 | comp := testSession
187 | comp.CalculateID()
188 | comp.CalculateContentHash()
189 |
190 | request.RetroArchVersion = "0123456789ABCDEF0123456789ABCDEF_INVALID"
191 |
192 | repoMock.On("GetByID", mock.MatchedBy(
193 | func(s string) bool {
194 | return s == comp.ID
195 | })).Return(&comp, nil)
196 |
197 | newSession, err := sessionDomain.Add(&request, testIP)
198 | require.Error(t, err)
199 | assert.Nil(t, newSession)
200 | assert.True(t, errors.Is(err, ErrSessionRejected))
201 | }
202 |
203 | func TestSessionDomainAddSessionTypeCreate(t *testing.T) {
204 | sessionDomain, repoMock := setupSessionDomain(t)
205 |
206 | request := testRequest
207 | comp := testSession
208 | comp.CalculateID()
209 | comp.CalculateContentHash()
210 |
211 | repoMock.On("GetByID", mock.MatchedBy(
212 | func(s string) bool {
213 | return s == comp.ID
214 | })).Return(nil, nil)
215 |
216 | repoMock.On("Create", mock.MatchedBy(
217 | func(s *entity.Session) bool {
218 | return s.ID == comp.ID && s.ContentHash == comp.ContentHash
219 | })).Return(nil)
220 |
221 | newSession, err := sessionDomain.Add(&request, testIP)
222 | require.NoError(t, err)
223 | require.NotNil(t, newSession)
224 | assert.Equal(t, comp.ID, newSession.ID)
225 | assert.Equal(t, comp.ContentHash, newSession.ContentHash)
226 | }
227 |
228 | func TestSessionDomainAddSessionTypeCreateShouldSetDefaultUsername(t *testing.T) {
229 | sessionDomain, repoMock := setupSessionDomain(t)
230 |
231 | request := testRequest
232 | request.Username = ""
233 |
234 | comp := testSession
235 | comp.Username = "Anonymous"
236 | comp.CalculateID()
237 | comp.CalculateContentHash()
238 |
239 | repoMock.On("GetByID", mock.MatchedBy(
240 | func(s string) bool {
241 | return s == comp.ID
242 | })).Return(nil, nil)
243 |
244 | repoMock.On("Create", mock.MatchedBy(
245 | func(s *entity.Session) bool {
246 | return s.ID == comp.ID && s.ContentHash == comp.ContentHash
247 | })).Return(nil)
248 |
249 | newSession, err := sessionDomain.Add(&request, testIP)
250 | require.NoError(t, err)
251 | require.NotNil(t, newSession)
252 | assert.Equal(t, comp.ID, newSession.ID)
253 | assert.Equal(t, comp.ContentHash, newSession.ContentHash)
254 | }
255 |
256 | func TestSessionDomainAddSessionTypeUpdate(t *testing.T) {
257 | sessionDomain, repoMock := setupSessionDomain(t)
258 |
259 | request := testRequest
260 | comp := testSession
261 | comp.CalculateID()
262 | comp.CalculateContentHash()
263 |
264 | request.GameCRC = "88888888"
265 |
266 | repoMock.On("GetByID", mock.MatchedBy(
267 | func(s string) bool {
268 | return s == comp.ID
269 | })).Return(&comp, nil)
270 |
271 | repoMock.On("Update", mock.MatchedBy(
272 | func(s *entity.Session) bool {
273 | return s.ID == comp.ID && s.ContentHash != comp.ContentHash
274 | })).Return(nil)
275 |
276 | newSession, err := sessionDomain.Add(&request, testIP)
277 | require.NoError(t, err)
278 | require.NotNil(t, newSession)
279 | assert.Equal(t, comp.ID, newSession.ID)
280 | assert.NotEqual(t, comp.ContentHash, newSession.ContentHash)
281 | }
282 |
283 | func TestSessionDomainAddSessionTypeTouch(t *testing.T) {
284 | sessionDomain, repoMock := setupSessionDomain(t)
285 |
286 | request := testRequest
287 | comp := testSession
288 | comp.CalculateID()
289 | comp.CalculateContentHash()
290 |
291 | repoMock.On("GetByID", mock.MatchedBy(
292 | func(s string) bool {
293 | return s == comp.ID
294 | })).Return(&comp, nil)
295 |
296 | repoMock.On("Touch", mock.MatchedBy(
297 | func(id string) bool {
298 | return id == comp.ID
299 | })).Return(nil)
300 |
301 | newSession, err := sessionDomain.Add(&request, testIP)
302 | require.NoError(t, err)
303 | require.NotNil(t, newSession)
304 | assert.Equal(t, comp.ID, newSession.ID)
305 | assert.Equal(t, comp.ContentHash, newSession.ContentHash)
306 | }
307 |
308 | func TestSessionDomainAddSessionTypeUpdateRateLimit(t *testing.T) {
309 | sessionDomain, repoMock := setupSessionDomain(t)
310 |
311 | request := testRequest
312 | comp := testSession
313 | comp.UpdatedAt = time.Now().Add(-4 * time.Second)
314 | comp.CalculateID()
315 | comp.CalculateContentHash()
316 |
317 | request.GameCRC = "88888888"
318 |
319 | repoMock.On("GetByID", mock.MatchedBy(
320 | func(s string) bool {
321 | return s == comp.ID
322 | })).Return(&comp, nil)
323 |
324 | repoMock.On("Update", mock.MatchedBy(
325 | func(s *entity.Session) bool {
326 | return s.ID == comp.ID && s.ContentHash != comp.ContentHash
327 | })).Return(nil)
328 |
329 | newSession, err := sessionDomain.Add(&request, testIP)
330 | require.Error(t, err)
331 | assert.True(t, errors.Is(err, ErrRateLimited))
332 | assert.Nil(t, newSession)
333 | }
334 |
335 | func TestSessionDomainAddSessionTypeTouchRateLimit(t *testing.T) {
336 | sessionDomain, repoMock := setupSessionDomain(t)
337 |
338 | request := testRequest
339 | comp := testSession
340 | comp.UpdatedAt = time.Now().Add(-4 * time.Second)
341 | comp.CalculateID()
342 | comp.CalculateContentHash()
343 |
344 | repoMock.On("GetByID", mock.MatchedBy(
345 | func(s string) bool {
346 | return s == comp.ID
347 | })).Return(&comp, nil)
348 |
349 | repoMock.On("Touch", mock.MatchedBy(
350 | func(id string) bool {
351 | return id == comp.ID
352 | })).Return(nil)
353 |
354 | newSession, err := sessionDomain.Add(&request, testIP)
355 | require.Error(t, err)
356 | assert.True(t, errors.Is(err, ErrRateLimited))
357 | assert.Nil(t, newSession)
358 | }
359 |
--------------------------------------------------------------------------------
/domain/sessiondomain.go:
--------------------------------------------------------------------------------
1 | package domain
2 |
3 | import (
4 | "bytes"
5 | "errors"
6 | "fmt"
7 | "net"
8 | "strings"
9 | "time"
10 |
11 | "github.com/libretro/netplay-lobby-server-go/model/entity"
12 | )
13 |
14 | // SessionDeadline is lifespan of a session that hasn't recieved any updated in seconds.
15 | const SessionDeadline = 60
16 |
17 | // RateLimit is the maximal rate a client can send an update (every five seconds)
18 | const RateLimit = 5
19 |
20 | // requestType enum
21 | type requestType int
22 |
23 | // SessionAddType enum value
24 | const (
25 | SessionCreate requestType = iota
26 | SessionUpdate
27 | SessionTouch
28 | )
29 |
30 | // AddSessionRequest defines the request for the SessionDomain.Add() request.
31 | type AddSessionRequest struct {
32 | Username string `form:"username"`
33 | CoreName string `form:"core_name"`
34 | CoreVersion string `form:"core_version"`
35 | GameName string `form:"game_name"`
36 | GameCRC string `form:"game_crc"`
37 | Port uint16 `form:"port"`
38 | MITMServer string `form:"mitm_server"`
39 | HasPassword bool `form:"has_password"` // 1/0 (Can it be bound to bool?)
40 | HasSpectatePassword bool `form:"has_spectate_password"`
41 | ForceMITM bool `form:"force_mitm"`
42 | RetroArchVersion string `form:"retroarch_version"`
43 | Frontend string `form:"frontend"`
44 | SubsystemName string `form:"subsystem_name"`
45 | MITMSession string `form:"mitm_session"`
46 | MITMCustomServer string `form:"mitm_custom_addr"`
47 | MITMCustomPort uint16 `form:"mitm_custom_port"`
48 | PlayerCount *int16 `form:"player_count"`
49 | SpectatorCount *int16 `form:"spectator_count"`
50 | }
51 |
52 | // ErrSessionRejected is thrown when a session got rejected by the domain logic.
53 | var ErrSessionRejected = errors.New("Session rejected")
54 |
55 | // ErrRateLimited is thrown when the rate limit is reached for a particular session.
56 | var ErrRateLimited = errors.New("Rate limit reached")
57 |
58 | // SessionRepository interface to decouple the domain logic from the repository code.
59 | type SessionRepository interface {
60 | Create(s *entity.Session) error
61 | GetByID(id string) (*entity.Session, error)
62 | GetByRoomID(roomID int32) (*entity.Session, error)
63 | GetAll(deadline time.Time) ([]entity.Session, error)
64 | Update(s *entity.Session) error
65 | Touch(s *entity.Session) error
66 | PurgeOld(deadline time.Time) error
67 | }
68 |
69 | // SessionDomain abstracts the domain logic for netplay session handling.
70 | type SessionDomain struct {
71 | sessionRepo SessionRepository
72 | geopip2Domain *GeoIP2Domain
73 | validationDomain *ValidationDomain
74 | mitmDomain *MitmDomain
75 | }
76 |
77 | // NewSessionDomain returns an initalized SessionDomain struct.
78 | func NewSessionDomain(
79 | sessionRepo SessionRepository,
80 | geoIP2Domain *GeoIP2Domain,
81 | validationDomain *ValidationDomain,
82 | mitmDomain *MitmDomain) *SessionDomain {
83 | return &SessionDomain{sessionRepo, geoIP2Domain, validationDomain, mitmDomain}
84 | }
85 |
86 | // Add adds or updates a session, based on the incoming request from the given IP.
87 | // Returns ErrSessionRejected if session got rejected.
88 | // Returns ErrRateLimited if rate limit for a session got reached.
89 | func (d *SessionDomain) Add(request *AddSessionRequest, ip net.IP) (*entity.Session, error) {
90 | var err error
91 | var savedSession *entity.Session
92 | var requestType requestType = SessionCreate
93 |
94 | session := d.parseSession(request, ip)
95 |
96 | if session.IP == nil || session.Port == 0 {
97 | return nil, errors.New("IP or port not set")
98 | }
99 |
100 | // Decide if this is a CREATE, UPDATE or TOUCH operation
101 | session.CalculateID()
102 | session.CalculateContentHash()
103 | if savedSession, err = d.sessionRepo.GetByID(session.ID); err != nil {
104 | return nil, fmt.Errorf("Can't get saved session: %w", err)
105 | }
106 | if savedSession != nil {
107 | session.RoomID = savedSession.RoomID
108 | session.Country = savedSession.Country
109 | session.Connectable = savedSession.Connectable
110 | session.IsRetroArch = savedSession.IsRetroArch
111 | session.CreatedAt = savedSession.CreatedAt
112 | session.UpdatedAt = savedSession.UpdatedAt
113 | if savedSession.ContentHash != session.ContentHash {
114 | requestType = SessionUpdate
115 | } else {
116 | requestType = SessionTouch
117 | }
118 | }
119 |
120 | // Ratelimit on UPDATE or TOUCH
121 | if requestType == SessionUpdate || requestType == SessionTouch {
122 | threshold := time.Now().Add(-5 * time.Second)
123 | if savedSession.UpdatedAt.After(threshold) {
124 | return nil, ErrRateLimited
125 | }
126 | }
127 |
128 | if requestType == SessionCreate || requestType == SessionUpdate {
129 | // Validate session on CREATE and UPDATE
130 | if !d.validateSession(session) {
131 | return nil, ErrSessionRejected
132 | }
133 | }
134 |
135 | // Persist session changes
136 | switch requestType {
137 | case SessionCreate:
138 | if session.Country, err = d.geopip2Domain.GetCountryCodeForIP(session.IP); err != nil {
139 | return nil, fmt.Errorf("Can't find country for given IP %s: %w", session.IP, err)
140 | }
141 |
142 | d.trySessionConnect(session)
143 |
144 | if err = d.sessionRepo.Create(session); err != nil {
145 | return nil, fmt.Errorf("Can't create new session: %w", err)
146 | }
147 | case SessionUpdate:
148 | d.trySessionConnect(session)
149 |
150 | if err = d.sessionRepo.Update(session); err != nil {
151 | return nil, fmt.Errorf("Can't update old session: %w", err)
152 | }
153 | case SessionTouch:
154 | if !session.Connectable {
155 | d.trySessionConnect(session)
156 | if session.Connectable {
157 | if err = d.sessionRepo.Update(session); err != nil {
158 | return nil, fmt.Errorf("Can't update old session: %w", err)
159 | }
160 | break
161 | }
162 | }
163 |
164 | if err = d.sessionRepo.Touch(session); err != nil {
165 | return nil, fmt.Errorf("Can't touch old session: %w", err)
166 | }
167 | }
168 |
169 | return session, nil
170 | }
171 |
172 | // Get returns the session with the given RoomID
173 | func (d *SessionDomain) Get(roomID int32) (*entity.Session, error) {
174 | session, err := d.sessionRepo.GetByRoomID(roomID)
175 | if err != nil {
176 | return nil, err
177 | }
178 |
179 | return session, nil
180 | }
181 |
182 | // List returns a list of all sessions that are currently being hosted
183 | func (d *SessionDomain) List() ([]entity.Session, error) {
184 | sessions, err := d.sessionRepo.GetAll(d.getDeadline())
185 | if err != nil {
186 | return nil, err
187 | }
188 |
189 | return sessions, nil
190 | }
191 |
192 | // PurgeOld removes all sessions that have not been updated for longer than 45 seconds.
193 | func (d *SessionDomain) PurgeOld() error {
194 | if err := d.sessionRepo.PurgeOld(d.getDeadline()); err != nil {
195 | return err
196 | }
197 |
198 | return nil
199 | }
200 |
201 | // parseSession turns a request into a session information that can be compared to a persisted session
202 | func (d *SessionDomain) parseSession(req *AddSessionRequest, ip net.IP) *entity.Session {
203 | var hostMethod entity.HostMethod = entity.HostMethodUnknown
204 | var mitmHandle string = ""
205 | var mitmAddress string = ""
206 | var mitmPort uint16 = 0
207 | var mitmSession string = ""
208 |
209 | // Set default username
210 | if req.Username == "" {
211 | req.Username = "Anonymous"
212 | }
213 |
214 | if req.ForceMITM && req.MITMServer != "" && req.MITMSession != "" {
215 | if req.MITMServer == "custom" {
216 | if req.MITMCustomServer != "" && req.MITMCustomPort != 0 {
217 | hostMethod = entity.HostMethodMITM
218 | mitmHandle = req.MITMServer
219 | mitmAddress = req.MITMCustomServer
220 | mitmPort = req.MITMCustomPort
221 | mitmSession = req.MITMSession
222 | }
223 | } else {
224 | if info := d.mitmDomain.GetInfo(req.MITMServer); info != nil {
225 | hostMethod = entity.HostMethodMITM
226 | mitmHandle = req.MITMServer
227 | mitmAddress = info.Address
228 | mitmPort = info.Port
229 | mitmSession = req.MITMSession
230 | }
231 | }
232 | }
233 |
234 | // Fill player counts to -1 if not present.
235 | plcnt := int16(-1)
236 | if req.PlayerCount != nil {
237 | plcnt = *req.PlayerCount
238 | }
239 | spcnt := int16(-1)
240 | if req.SpectatorCount != nil {
241 | spcnt = *req.SpectatorCount
242 | }
243 |
244 | return &entity.Session{
245 | Username: req.Username,
246 | GameName: req.GameName,
247 | GameCRC: strings.ToUpper(req.GameCRC),
248 | CoreName: req.CoreName,
249 | CoreVersion: req.CoreVersion,
250 | SubsystemName: req.SubsystemName,
251 | RetroArchVersion: req.RetroArchVersion,
252 | Frontend: req.Frontend,
253 | IP: ip,
254 | Port: req.Port,
255 | MitmHandle: mitmHandle,
256 | MitmAddress: mitmAddress,
257 | MitmPort: mitmPort,
258 | MitmSession: mitmSession,
259 | HostMethod: hostMethod,
260 | HasPassword: req.HasPassword,
261 | HasSpectatePassword: req.HasSpectatePassword,
262 | PlayerCount: plcnt,
263 | SpectatorCount: spcnt,
264 | }
265 | }
266 |
267 | // validateSession validates an incoming session
268 | func (d *SessionDomain) validateSession(s *entity.Session) bool {
269 | if len(s.Username) > 32 ||
270 | len(s.CoreName) > 255 ||
271 | len(s.GameName) > 255 ||
272 | len(s.GameCRC) != 8 ||
273 | len(s.RetroArchVersion) > 32 ||
274 | len(s.CoreVersion) > 255 ||
275 | len(s.SubsystemName) > 255 ||
276 | len(s.Frontend) > 255 ||
277 | len(s.MitmSession) > 32 {
278 | return false
279 | }
280 |
281 | if !d.validationDomain.ValidateString(s.Username) ||
282 | !d.validationDomain.ValidateString(s.CoreName) ||
283 | !d.validationDomain.ValidateString(s.CoreVersion) ||
284 | !d.validationDomain.ValidateString(s.Frontend) ||
285 | !d.validationDomain.ValidateString(s.SubsystemName) ||
286 | !d.validationDomain.ValidateString(s.RetroArchVersion) {
287 | return false
288 | }
289 |
290 | return true
291 | }
292 |
293 | // trySessionConnect tests the session to see whether it's connectable and whether it's RetroArch
294 | func (d *SessionDomain) trySessionConnect(s *entity.Session) error {
295 | s.Connectable = true
296 | s.IsRetroArch = true
297 |
298 | // If it's MITM, assume both connectable and RetroArch
299 | if s.HostMethod == entity.HostMethodMITM {
300 | return nil
301 | }
302 |
303 | address := fmt.Sprintf("%s:%d", s.IP, s.Port)
304 | conn, err := net.DialTimeout("tcp", address, time.Second * 3)
305 | if err != nil {
306 | s.Connectable = false
307 | return err
308 | }
309 |
310 | ranp := []byte{0x52,0x41,0x4E,0x50} // RANP
311 | full := []byte{0x46,0x55,0x4C,0x4C} // FULL
312 | poke := []byte{0x50,0x4F,0x4B,0x45} // POKE
313 | magic := make([]byte, 4)
314 |
315 | // Ignore write errors
316 | conn.SetWriteDeadline(time.Now().Add(time.Second * 3))
317 | conn.Write(poke)
318 |
319 | conn.SetReadDeadline(time.Now().Add(time.Second * 3))
320 | read, err := conn.Read(magic)
321 |
322 | conn.Close()
323 |
324 | // Assume it's RetroArch on recv error
325 | if err != nil || read == 0 {
326 | return err
327 | }
328 |
329 | // Assume it's not RetroArch on incomplete magic
330 | if read != len(magic) {
331 | s.IsRetroArch = false
332 | } else if !bytes.Equal(magic, ranp) && !bytes.Equal(magic, full) {
333 | s.IsRetroArch = false
334 | }
335 |
336 | return nil
337 | }
338 |
339 | func (d *SessionDomain) getDeadline() time.Time {
340 | return time.Now().Add(-SessionDeadline * time.Second)
341 | }
342 |
343 | // GetTunnel returns a tunnel's address/port pair.
344 | func (d *SessionDomain) GetMitm() *MitmDomain {
345 | return d.mitmDomain
346 | }
347 |
--------------------------------------------------------------------------------
/go.sum:
--------------------------------------------------------------------------------
1 | cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
2 | github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
3 | github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
4 | github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
5 | github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
6 | github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
7 | github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
8 | github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
9 | github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
10 | github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
11 | github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
12 | github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
13 | github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
14 | github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
15 | github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
16 | github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
17 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
18 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
19 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
20 | github.com/denisenkom/go-mssqldb v0.0.0-20191124224453-732737034ffd h1:83Wprp6ROGeiHFAP8WJdI2RoxALQYgdllERc3N5N2DM=
21 | github.com/denisenkom/go-mssqldb v0.0.0-20191124224453-732737034ffd/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU=
22 | github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
23 | github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
24 | github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
25 | github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5 h1:Yzb9+7DPaBjB8zlTR87/ElzFsnQfuHnVUVqpZZIcV5Y=
26 | github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5/go.mod h1:a2zkGnVExMxdzMo3M0Hi/3sEU+cWnZpSni0O6/Yb/P0=
27 | github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
28 | github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
29 | github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
30 | github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
31 | github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
32 | github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
33 | github.com/go-sql-driver/mysql v1.4.1 h1:g24URVg0OFbNUTx9qqY1IRZ9D9z3iPyi5zKhQZpNwpA=
34 | github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
35 | github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
36 | github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
37 | github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
38 | github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe h1:lXe2qZdvpiX5WZkZR4hgp4KJVfY3nMkvmwbVkpv1rVY=
39 | github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0=
40 | github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
41 | github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
42 | github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
43 | github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
44 | github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
45 | github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
46 | github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
47 | github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
48 | github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
49 | github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
50 | github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
51 | github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
52 | github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
53 | github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
54 | github.com/jinzhu/gorm v1.9.12 h1:Drgk1clyWT9t9ERbzHza6Mj/8FY/CqMyVzOiHviMo6Q=
55 | github.com/jinzhu/gorm v1.9.12/go.mod h1:vhTjlKSJUTWNtcbQtrMBFCxy7eXTzeCAzfL5fBZT/Qs=
56 | github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
57 | github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
58 | github.com/jinzhu/now v1.0.1 h1:HjfetcXq097iXP0uoPCdnM4Efp5/9MsM0/M+XOTeR3M=
59 | github.com/jinzhu/now v1.0.1/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
60 | github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
61 | github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
62 | github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
63 | github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
64 | github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
65 | github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
66 | github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
67 | github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
68 | github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
69 | github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
70 | github.com/labstack/echo v3.3.10+incompatible h1:pGRcYk231ExFAyoAjAfD85kQzRJCRI8bbnE7CX5OEgg=
71 | github.com/labstack/echo v3.3.10+incompatible/go.mod h1:0INS7j/VjnFxD4E2wkz67b8cVwCLbBmJyDaka6Cmk1s=
72 | github.com/labstack/echo/v4 v4.1.13 h1:JYgKq6NQQSaKbQcsOadAKX1kUVLCUzLGwu8sxN5tC34=
73 | github.com/labstack/echo/v4 v4.1.13/go.mod h1:3WZNypykZ3tnqpF2Qb4fPg27XDunFqgP3HGDmCMgv7U=
74 | github.com/labstack/gommon v0.3.0 h1:JEeO0bvc78PKdyHxloTKiF8BD5iGrH8T6MSeGvSgob0=
75 | github.com/labstack/gommon v0.3.0/go.mod h1:MULnywXg0yavhxWKc+lOruYdAhDwPK9wf0OL7NoOu+k=
76 | github.com/lib/pq v1.1.1 h1:sJZmqHoEaY7f+NPP8pgLB/WxulyR3fewgCM2qaSlBb4=
77 | github.com/lib/pq v1.1.1/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
78 | github.com/magiconair/properties v1.8.1 h1:ZC2Vc7/ZFkGmsVC9KvOjumD+G5lXy2RtTKyzRKO2BQ4=
79 | github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
80 | github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
81 | github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA=
82 | github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
83 | github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
84 | github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ=
85 | github.com/mattn/go-isatty v0.0.11 h1:FxPOTFNqGkuDUGi3H/qkUbQO4ZiBa2brKq5r0l8TGeM=
86 | github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE=
87 | github.com/mattn/go-sqlite3 v2.0.1+incompatible h1:xQ15muvnzGBHpIpdrNi1DA5x0+TcBZzsIDwmw9uTHzw=
88 | github.com/mattn/go-sqlite3 v2.0.1+incompatible/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
89 | github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
90 | github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
91 | github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
92 | github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
93 | github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
94 | github.com/oschwald/geoip2-golang v1.4.0/go.mod h1:8QwxJvRImBH+Zl6Aa6MaIcs5YdlZSTKtzmPGzQqi9ng=
95 | github.com/oschwald/maxminddb-golang v1.6.0 h1:KAJSjdHQ8Kv45nFIbtoLGrGWqHFajOIm7skTyz/+Dls=
96 | github.com/oschwald/maxminddb-golang v1.6.0/go.mod h1:DUJFucBg2cvqx42YmDa/+xHvb0elJtOm3o4aFQ/nb/w=
97 | github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc=
98 | github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
99 | github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
100 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
101 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
102 | github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
103 | github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso=
104 | github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
105 | github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
106 | github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro=
107 | github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
108 | github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
109 | github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
110 | github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
111 | github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
112 | github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
113 | github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
114 | github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
115 | github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
116 | github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
117 | github.com/spf13/afero v1.1.2 h1:m8/z1t7/fwjysjQRYbP0RD+bUIF/8tJwPdEZsI83ACI=
118 | github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
119 | github.com/spf13/cast v1.3.0 h1:oget//CVOEoFewqQxwr0Ej5yjygnqGkvggSE/gB35Q8=
120 | github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
121 | github.com/spf13/jwalterweatherman v1.0.0 h1:XHEdyB+EcvlqZamSM4ZOMGlc93t6AcsBEu9Gc1vn7yk=
122 | github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
123 | github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
124 | github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
125 | github.com/spf13/viper v1.6.2 h1:7aKfF+e8/k68gda3LOjo5RxiUqddoFxVq4BKBPrxk5E=
126 | github.com/spf13/viper v1.6.2/go.mod h1:t3iDnF5Jlj76alVNuyFBk5oUMCvsrkbvZK0WQdfDi5k=
127 | github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
128 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
129 | github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A=
130 | github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
131 | github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
132 | github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
133 | github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
134 | github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s=
135 | github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
136 | github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
137 | github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc=
138 | github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
139 | github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
140 | github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
141 | github.com/valyala/fasttemplate v1.1.0 h1:RZqt0yGBsps8NGvLSGW804QQqCUYYLsaOjTVHy1Ocw4=
142 | github.com/valyala/fasttemplate v1.1.0/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
143 | github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
144 | github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
145 | go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
146 | go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
147 | go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
148 | go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
149 | golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
150 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
151 | golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
152 | golang.org/x/crypto v0.0.0-20191205180655-e7c4368fe9dd h1:GGJVjV8waZKRHrgwvtH66z9ZGVurTD1MT0n1Bb+q4aM=
153 | golang.org/x/crypto v0.0.0-20191205180655-e7c4368fe9dd/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
154 | golang.org/x/crypto v0.0.0-20191227163750-53104e6ec876 h1:sKJQZMuxjOAR/Uo2LBfU90onWEf1dF4C+0hPJCc9Mpc=
155 | golang.org/x/crypto v0.0.0-20191227163750-53104e6ec876/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
156 | golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
157 | golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
158 | golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
159 | golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
160 | golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
161 | golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
162 | golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
163 | golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
164 | golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
165 | golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553 h1:efeOvDhwQ29Dj3SdAV/MJf8oukgn+8D8WgaCaRMchF8=
166 | golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
167 | golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
168 | golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
169 | golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
170 | golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
171 | golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
172 | golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
173 | golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
174 | golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
175 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
176 | golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
177 | golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
178 | golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
179 | golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
180 | golang.org/x/sys v0.0.0-20191224085550-c709ea063b76 h1:Dho5nD6R3PcW2SH1or8vS0dszDaXRxIw55lBX7XiE5g=
181 | golang.org/x/sys v0.0.0-20191224085550-c709ea063b76/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
182 | golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8 h1:JA8d3MPx/IToSyXZG/RhwYEtfrKO1Fxrqe8KrkiLXKM=
183 | golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
184 | golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
185 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
186 | golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
187 | golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
188 | golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
189 | golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
190 | golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
191 | golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
192 | golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
193 | golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
194 | google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
195 | google.golang.org/appengine v1.4.0 h1:/wp5JvzpHIxhs/dumFmF7BXTf3Z+dd4uXta4kVyO508=
196 | google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
197 | google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
198 | google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
199 | google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
200 | gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
201 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
202 | gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
203 | gopkg.in/ini.v1 v1.51.0 h1:AQvPpx3LzTDM0AjnIRlVFwFFGC+npRopjZxLJj6gdno=
204 | gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
205 | gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
206 | gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
207 | gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
208 | gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
209 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
210 | gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I=
211 | gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
212 | honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
213 | rsc.io/quote v1.5.2/go.mod h1:LzX7hefJvL54yjefDEDHNONDjII0t9xZLPXsUe+TKr0=
214 | rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
215 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU AFFERO GENERAL PUBLIC LICENSE
2 | Version 3, 19 November 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU Affero General Public License is a free, copyleft license for
11 | software and other kinds of works, specifically designed to ensure
12 | cooperation with the community in the case of network server software.
13 |
14 | The licenses for most software and other practical works are designed
15 | to take away your freedom to share and change the works. By contrast,
16 | our General Public Licenses are intended to guarantee your freedom to
17 | share and change all versions of a program--to make sure it remains free
18 | software for all its users.
19 |
20 | When we speak of free software, we are referring to freedom, not
21 | price. Our General Public Licenses are designed to make sure that you
22 | have the freedom to distribute copies of free software (and charge for
23 | them if you wish), that you receive source code or can get it if you
24 | want it, that you can change the software or use pieces of it in new
25 | free programs, and that you know you can do these things.
26 |
27 | Developers that use our General Public Licenses protect your rights
28 | with two steps: (1) assert copyright on the software, and (2) offer
29 | you this License which gives you legal permission to copy, distribute
30 | and/or modify the software.
31 |
32 | A secondary benefit of defending all users' freedom is that
33 | improvements made in alternate versions of the program, if they
34 | receive widespread use, become available for other developers to
35 | incorporate. Many developers of free software are heartened and
36 | encouraged by the resulting cooperation. However, in the case of
37 | software used on network servers, this result may fail to come about.
38 | The GNU General Public License permits making a modified version and
39 | letting the public access it on a server without ever releasing its
40 | source code to the public.
41 |
42 | The GNU Affero General Public License is designed specifically to
43 | ensure that, in such cases, the modified source code becomes available
44 | to the community. It requires the operator of a network server to
45 | provide the source code of the modified version running there to the
46 | users of that server. Therefore, public use of a modified version, on
47 | a publicly accessible server, gives the public access to the source
48 | code of the modified version.
49 |
50 | An older license, called the Affero General Public License and
51 | published by Affero, was designed to accomplish similar goals. This is
52 | a different license, not a version of the Affero GPL, but Affero has
53 | released a new version of the Affero GPL which permits relicensing under
54 | this license.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | TERMS AND CONDITIONS
60 |
61 | 0. Definitions.
62 |
63 | "This License" refers to version 3 of the GNU Affero General Public License.
64 |
65 | "Copyright" also means copyright-like laws that apply to other kinds of
66 | works, such as semiconductor masks.
67 |
68 | "The Program" refers to any copyrightable work licensed under this
69 | License. Each licensee is addressed as "you". "Licensees" and
70 | "recipients" may be individuals or organizations.
71 |
72 | To "modify" a work means to copy from or adapt all or part of the work
73 | in a fashion requiring copyright permission, other than the making of an
74 | exact copy. The resulting work is called a "modified version" of the
75 | earlier work or a work "based on" the earlier work.
76 |
77 | A "covered work" means either the unmodified Program or a work based
78 | on the Program.
79 |
80 | To "propagate" a work means to do anything with it that, without
81 | permission, would make you directly or secondarily liable for
82 | infringement under applicable copyright law, except executing it on a
83 | computer or modifying a private copy. Propagation includes copying,
84 | distribution (with or without modification), making available to the
85 | public, and in some countries other activities as well.
86 |
87 | To "convey" a work means any kind of propagation that enables other
88 | parties to make or receive copies. Mere interaction with a user through
89 | a computer network, with no transfer of a copy, is not conveying.
90 |
91 | An interactive user interface displays "Appropriate Legal Notices"
92 | to the extent that it includes a convenient and prominently visible
93 | feature that (1) displays an appropriate copyright notice, and (2)
94 | tells the user that there is no warranty for the work (except to the
95 | extent that warranties are provided), that licensees may convey the
96 | work under this License, and how to view a copy of this License. If
97 | the interface presents a list of user commands or options, such as a
98 | menu, a prominent item in the list meets this criterion.
99 |
100 | 1. Source Code.
101 |
102 | The "source code" for a work means the preferred form of the work
103 | for making modifications to it. "Object code" means any non-source
104 | form of a work.
105 |
106 | A "Standard Interface" means an interface that either is an official
107 | standard defined by a recognized standards body, or, in the case of
108 | interfaces specified for a particular programming language, one that
109 | is widely used among developers working in that language.
110 |
111 | The "System Libraries" of an executable work include anything, other
112 | than the work as a whole, that (a) is included in the normal form of
113 | packaging a Major Component, but which is not part of that Major
114 | Component, and (b) serves only to enable use of the work with that
115 | Major Component, or to implement a Standard Interface for which an
116 | implementation is available to the public in source code form. A
117 | "Major Component", in this context, means a major essential component
118 | (kernel, window system, and so on) of the specific operating system
119 | (if any) on which the executable work runs, or a compiler used to
120 | produce the work, or an object code interpreter used to run it.
121 |
122 | The "Corresponding Source" for a work in object code form means all
123 | the source code needed to generate, install, and (for an executable
124 | work) run the object code and to modify the work, including scripts to
125 | control those activities. However, it does not include the work's
126 | System Libraries, or general-purpose tools or generally available free
127 | programs which are used unmodified in performing those activities but
128 | which are not part of the work. For example, Corresponding Source
129 | includes interface definition files associated with source files for
130 | the work, and the source code for shared libraries and dynamically
131 | linked subprograms that the work is specifically designed to require,
132 | such as by intimate data communication or control flow between those
133 | subprograms and other parts of the work.
134 |
135 | The Corresponding Source need not include anything that users
136 | can regenerate automatically from other parts of the Corresponding
137 | Source.
138 |
139 | The Corresponding Source for a work in source code form is that
140 | same work.
141 |
142 | 2. Basic Permissions.
143 |
144 | All rights granted under this License are granted for the term of
145 | copyright on the Program, and are irrevocable provided the stated
146 | conditions are met. This License explicitly affirms your unlimited
147 | permission to run the unmodified Program. The output from running a
148 | covered work is covered by this License only if the output, given its
149 | content, constitutes a covered work. This License acknowledges your
150 | rights of fair use or other equivalent, as provided by copyright law.
151 |
152 | You may make, run and propagate covered works that you do not
153 | convey, without conditions so long as your license otherwise remains
154 | in force. You may convey covered works to others for the sole purpose
155 | of having them make modifications exclusively for you, or provide you
156 | with facilities for running those works, provided that you comply with
157 | the terms of this License in conveying all material for which you do
158 | not control copyright. Those thus making or running the covered works
159 | for you must do so exclusively on your behalf, under your direction
160 | and control, on terms that prohibit them from making any copies of
161 | your copyrighted material outside their relationship with you.
162 |
163 | Conveying under any other circumstances is permitted solely under
164 | the conditions stated below. Sublicensing is not allowed; section 10
165 | makes it unnecessary.
166 |
167 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
168 |
169 | No covered work shall be deemed part of an effective technological
170 | measure under any applicable law fulfilling obligations under article
171 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
172 | similar laws prohibiting or restricting circumvention of such
173 | measures.
174 |
175 | When you convey a covered work, you waive any legal power to forbid
176 | circumvention of technological measures to the extent such circumvention
177 | is effected by exercising rights under this License with respect to
178 | the covered work, and you disclaim any intention to limit operation or
179 | modification of the work as a means of enforcing, against the work's
180 | users, your or third parties' legal rights to forbid circumvention of
181 | technological measures.
182 |
183 | 4. Conveying Verbatim Copies.
184 |
185 | You may convey verbatim copies of the Program's source code as you
186 | receive it, in any medium, provided that you conspicuously and
187 | appropriately publish on each copy an appropriate copyright notice;
188 | keep intact all notices stating that this License and any
189 | non-permissive terms added in accord with section 7 apply to the code;
190 | keep intact all notices of the absence of any warranty; and give all
191 | recipients a copy of this License along with the Program.
192 |
193 | You may charge any price or no price for each copy that you convey,
194 | and you may offer support or warranty protection for a fee.
195 |
196 | 5. Conveying Modified Source Versions.
197 |
198 | You may convey a work based on the Program, or the modifications to
199 | produce it from the Program, in the form of source code under the
200 | terms of section 4, provided that you also meet all of these conditions:
201 |
202 | a) The work must carry prominent notices stating that you modified
203 | it, and giving a relevant date.
204 |
205 | b) The work must carry prominent notices stating that it is
206 | released under this License and any conditions added under section
207 | 7. This requirement modifies the requirement in section 4 to
208 | "keep intact all notices".
209 |
210 | c) You must license the entire work, as a whole, under this
211 | License to anyone who comes into possession of a copy. This
212 | License will therefore apply, along with any applicable section 7
213 | additional terms, to the whole of the work, and all its parts,
214 | regardless of how they are packaged. This License gives no
215 | permission to license the work in any other way, but it does not
216 | invalidate such permission if you have separately received it.
217 |
218 | d) If the work has interactive user interfaces, each must display
219 | Appropriate Legal Notices; however, if the Program has interactive
220 | interfaces that do not display Appropriate Legal Notices, your
221 | work need not make them do so.
222 |
223 | A compilation of a covered work with other separate and independent
224 | works, which are not by their nature extensions of the covered work,
225 | and which are not combined with it such as to form a larger program,
226 | in or on a volume of a storage or distribution medium, is called an
227 | "aggregate" if the compilation and its resulting copyright are not
228 | used to limit the access or legal rights of the compilation's users
229 | beyond what the individual works permit. Inclusion of a covered work
230 | in an aggregate does not cause this License to apply to the other
231 | parts of the aggregate.
232 |
233 | 6. Conveying Non-Source Forms.
234 |
235 | You may convey a covered work in object code form under the terms
236 | of sections 4 and 5, provided that you also convey the
237 | machine-readable Corresponding Source under the terms of this License,
238 | in one of these ways:
239 |
240 | a) Convey the object code in, or embodied in, a physical product
241 | (including a physical distribution medium), accompanied by the
242 | Corresponding Source fixed on a durable physical medium
243 | customarily used for software interchange.
244 |
245 | b) Convey the object code in, or embodied in, a physical product
246 | (including a physical distribution medium), accompanied by a
247 | written offer, valid for at least three years and valid for as
248 | long as you offer spare parts or customer support for that product
249 | model, to give anyone who possesses the object code either (1) a
250 | copy of the Corresponding Source for all the software in the
251 | product that is covered by this License, on a durable physical
252 | medium customarily used for software interchange, for a price no
253 | more than your reasonable cost of physically performing this
254 | conveying of source, or (2) access to copy the
255 | Corresponding Source from a network server at no charge.
256 |
257 | c) Convey individual copies of the object code with a copy of the
258 | written offer to provide the Corresponding Source. This
259 | alternative is allowed only occasionally and noncommercially, and
260 | only if you received the object code with such an offer, in accord
261 | with subsection 6b.
262 |
263 | d) Convey the object code by offering access from a designated
264 | place (gratis or for a charge), and offer equivalent access to the
265 | Corresponding Source in the same way through the same place at no
266 | further charge. You need not require recipients to copy the
267 | Corresponding Source along with the object code. If the place to
268 | copy the object code is a network server, the Corresponding Source
269 | may be on a different server (operated by you or a third party)
270 | that supports equivalent copying facilities, provided you maintain
271 | clear directions next to the object code saying where to find the
272 | Corresponding Source. Regardless of what server hosts the
273 | Corresponding Source, you remain obligated to ensure that it is
274 | available for as long as needed to satisfy these requirements.
275 |
276 | e) Convey the object code using peer-to-peer transmission, provided
277 | you inform other peers where the object code and Corresponding
278 | Source of the work are being offered to the general public at no
279 | charge under subsection 6d.
280 |
281 | A separable portion of the object code, whose source code is excluded
282 | from the Corresponding Source as a System Library, need not be
283 | included in conveying the object code work.
284 |
285 | A "User Product" is either (1) a "consumer product", which means any
286 | tangible personal property which is normally used for personal, family,
287 | or household purposes, or (2) anything designed or sold for incorporation
288 | into a dwelling. In determining whether a product is a consumer product,
289 | doubtful cases shall be resolved in favor of coverage. For a particular
290 | product received by a particular user, "normally used" refers to a
291 | typical or common use of that class of product, regardless of the status
292 | of the particular user or of the way in which the particular user
293 | actually uses, or expects or is expected to use, the product. A product
294 | is a consumer product regardless of whether the product has substantial
295 | commercial, industrial or non-consumer uses, unless such uses represent
296 | the only significant mode of use of the product.
297 |
298 | "Installation Information" for a User Product means any methods,
299 | procedures, authorization keys, or other information required to install
300 | and execute modified versions of a covered work in that User Product from
301 | a modified version of its Corresponding Source. The information must
302 | suffice to ensure that the continued functioning of the modified object
303 | code is in no case prevented or interfered with solely because
304 | modification has been made.
305 |
306 | If you convey an object code work under this section in, or with, or
307 | specifically for use in, a User Product, and the conveying occurs as
308 | part of a transaction in which the right of possession and use of the
309 | User Product is transferred to the recipient in perpetuity or for a
310 | fixed term (regardless of how the transaction is characterized), the
311 | Corresponding Source conveyed under this section must be accompanied
312 | by the Installation Information. But this requirement does not apply
313 | if neither you nor any third party retains the ability to install
314 | modified object code on the User Product (for example, the work has
315 | been installed in ROM).
316 |
317 | The requirement to provide Installation Information does not include a
318 | requirement to continue to provide support service, warranty, or updates
319 | for a work that has been modified or installed by the recipient, or for
320 | the User Product in which it has been modified or installed. Access to a
321 | network may be denied when the modification itself materially and
322 | adversely affects the operation of the network or violates the rules and
323 | protocols for communication across the network.
324 |
325 | Corresponding Source conveyed, and Installation Information provided,
326 | in accord with this section must be in a format that is publicly
327 | documented (and with an implementation available to the public in
328 | source code form), and must require no special password or key for
329 | unpacking, reading or copying.
330 |
331 | 7. Additional Terms.
332 |
333 | "Additional permissions" are terms that supplement the terms of this
334 | License by making exceptions from one or more of its conditions.
335 | Additional permissions that are applicable to the entire Program shall
336 | be treated as though they were included in this License, to the extent
337 | that they are valid under applicable law. If additional permissions
338 | apply only to part of the Program, that part may be used separately
339 | under those permissions, but the entire Program remains governed by
340 | this License without regard to the additional permissions.
341 |
342 | When you convey a copy of a covered work, you may at your option
343 | remove any additional permissions from that copy, or from any part of
344 | it. (Additional permissions may be written to require their own
345 | removal in certain cases when you modify the work.) You may place
346 | additional permissions on material, added by you to a covered work,
347 | for which you have or can give appropriate copyright permission.
348 |
349 | Notwithstanding any other provision of this License, for material you
350 | add to a covered work, you may (if authorized by the copyright holders of
351 | that material) supplement the terms of this License with terms:
352 |
353 | a) Disclaiming warranty or limiting liability differently from the
354 | terms of sections 15 and 16 of this License; or
355 |
356 | b) Requiring preservation of specified reasonable legal notices or
357 | author attributions in that material or in the Appropriate Legal
358 | Notices displayed by works containing it; or
359 |
360 | c) Prohibiting misrepresentation of the origin of that material, or
361 | requiring that modified versions of such material be marked in
362 | reasonable ways as different from the original version; or
363 |
364 | d) Limiting the use for publicity purposes of names of licensors or
365 | authors of the material; or
366 |
367 | e) Declining to grant rights under trademark law for use of some
368 | trade names, trademarks, or service marks; or
369 |
370 | f) Requiring indemnification of licensors and authors of that
371 | material by anyone who conveys the material (or modified versions of
372 | it) with contractual assumptions of liability to the recipient, for
373 | any liability that these contractual assumptions directly impose on
374 | those licensors and authors.
375 |
376 | All other non-permissive additional terms are considered "further
377 | restrictions" within the meaning of section 10. If the Program as you
378 | received it, or any part of it, contains a notice stating that it is
379 | governed by this License along with a term that is a further
380 | restriction, you may remove that term. If a license document contains
381 | a further restriction but permits relicensing or conveying under this
382 | License, you may add to a covered work material governed by the terms
383 | of that license document, provided that the further restriction does
384 | not survive such relicensing or conveying.
385 |
386 | If you add terms to a covered work in accord with this section, you
387 | must place, in the relevant source files, a statement of the
388 | additional terms that apply to those files, or a notice indicating
389 | where to find the applicable terms.
390 |
391 | Additional terms, permissive or non-permissive, may be stated in the
392 | form of a separately written license, or stated as exceptions;
393 | the above requirements apply either way.
394 |
395 | 8. Termination.
396 |
397 | You may not propagate or modify a covered work except as expressly
398 | provided under this License. Any attempt otherwise to propagate or
399 | modify it is void, and will automatically terminate your rights under
400 | this License (including any patent licenses granted under the third
401 | paragraph of section 11).
402 |
403 | However, if you cease all violation of this License, then your
404 | license from a particular copyright holder is reinstated (a)
405 | provisionally, unless and until the copyright holder explicitly and
406 | finally terminates your license, and (b) permanently, if the copyright
407 | holder fails to notify you of the violation by some reasonable means
408 | prior to 60 days after the cessation.
409 |
410 | Moreover, your license from a particular copyright holder is
411 | reinstated permanently if the copyright holder notifies you of the
412 | violation by some reasonable means, this is the first time you have
413 | received notice of violation of this License (for any work) from that
414 | copyright holder, and you cure the violation prior to 30 days after
415 | your receipt of the notice.
416 |
417 | Termination of your rights under this section does not terminate the
418 | licenses of parties who have received copies or rights from you under
419 | this License. If your rights have been terminated and not permanently
420 | reinstated, you do not qualify to receive new licenses for the same
421 | material under section 10.
422 |
423 | 9. Acceptance Not Required for Having Copies.
424 |
425 | You are not required to accept this License in order to receive or
426 | run a copy of the Program. Ancillary propagation of a covered work
427 | occurring solely as a consequence of using peer-to-peer transmission
428 | to receive a copy likewise does not require acceptance. However,
429 | nothing other than this License grants you permission to propagate or
430 | modify any covered work. These actions infringe copyright if you do
431 | not accept this License. Therefore, by modifying or propagating a
432 | covered work, you indicate your acceptance of this License to do so.
433 |
434 | 10. Automatic Licensing of Downstream Recipients.
435 |
436 | Each time you convey a covered work, the recipient automatically
437 | receives a license from the original licensors, to run, modify and
438 | propagate that work, subject to this License. You are not responsible
439 | for enforcing compliance by third parties with this License.
440 |
441 | An "entity transaction" is a transaction transferring control of an
442 | organization, or substantially all assets of one, or subdividing an
443 | organization, or merging organizations. If propagation of a covered
444 | work results from an entity transaction, each party to that
445 | transaction who receives a copy of the work also receives whatever
446 | licenses to the work the party's predecessor in interest had or could
447 | give under the previous paragraph, plus a right to possession of the
448 | Corresponding Source of the work from the predecessor in interest, if
449 | the predecessor has it or can get it with reasonable efforts.
450 |
451 | You may not impose any further restrictions on the exercise of the
452 | rights granted or affirmed under this License. For example, you may
453 | not impose a license fee, royalty, or other charge for exercise of
454 | rights granted under this License, and you may not initiate litigation
455 | (including a cross-claim or counterclaim in a lawsuit) alleging that
456 | any patent claim is infringed by making, using, selling, offering for
457 | sale, or importing the Program or any portion of it.
458 |
459 | 11. Patents.
460 |
461 | A "contributor" is a copyright holder who authorizes use under this
462 | License of the Program or a work on which the Program is based. The
463 | work thus licensed is called the contributor's "contributor version".
464 |
465 | A contributor's "essential patent claims" are all patent claims
466 | owned or controlled by the contributor, whether already acquired or
467 | hereafter acquired, that would be infringed by some manner, permitted
468 | by this License, of making, using, or selling its contributor version,
469 | but do not include claims that would be infringed only as a
470 | consequence of further modification of the contributor version. For
471 | purposes of this definition, "control" includes the right to grant
472 | patent sublicenses in a manner consistent with the requirements of
473 | this License.
474 |
475 | Each contributor grants you a non-exclusive, worldwide, royalty-free
476 | patent license under the contributor's essential patent claims, to
477 | make, use, sell, offer for sale, import and otherwise run, modify and
478 | propagate the contents of its contributor version.
479 |
480 | In the following three paragraphs, a "patent license" is any express
481 | agreement or commitment, however denominated, not to enforce a patent
482 | (such as an express permission to practice a patent or covenant not to
483 | sue for patent infringement). To "grant" such a patent license to a
484 | party means to make such an agreement or commitment not to enforce a
485 | patent against the party.
486 |
487 | If you convey a covered work, knowingly relying on a patent license,
488 | and the Corresponding Source of the work is not available for anyone
489 | to copy, free of charge and under the terms of this License, through a
490 | publicly available network server or other readily accessible means,
491 | then you must either (1) cause the Corresponding Source to be so
492 | available, or (2) arrange to deprive yourself of the benefit of the
493 | patent license for this particular work, or (3) arrange, in a manner
494 | consistent with the requirements of this License, to extend the patent
495 | license to downstream recipients. "Knowingly relying" means you have
496 | actual knowledge that, but for the patent license, your conveying the
497 | covered work in a country, or your recipient's use of the covered work
498 | in a country, would infringe one or more identifiable patents in that
499 | country that you have reason to believe are valid.
500 |
501 | If, pursuant to or in connection with a single transaction or
502 | arrangement, you convey, or propagate by procuring conveyance of, a
503 | covered work, and grant a patent license to some of the parties
504 | receiving the covered work authorizing them to use, propagate, modify
505 | or convey a specific copy of the covered work, then the patent license
506 | you grant is automatically extended to all recipients of the covered
507 | work and works based on it.
508 |
509 | A patent license is "discriminatory" if it does not include within
510 | the scope of its coverage, prohibits the exercise of, or is
511 | conditioned on the non-exercise of one or more of the rights that are
512 | specifically granted under this License. You may not convey a covered
513 | work if you are a party to an arrangement with a third party that is
514 | in the business of distributing software, under which you make payment
515 | to the third party based on the extent of your activity of conveying
516 | the work, and under which the third party grants, to any of the
517 | parties who would receive the covered work from you, a discriminatory
518 | patent license (a) in connection with copies of the covered work
519 | conveyed by you (or copies made from those copies), or (b) primarily
520 | for and in connection with specific products or compilations that
521 | contain the covered work, unless you entered into that arrangement,
522 | or that patent license was granted, prior to 28 March 2007.
523 |
524 | Nothing in this License shall be construed as excluding or limiting
525 | any implied license or other defenses to infringement that may
526 | otherwise be available to you under applicable patent law.
527 |
528 | 12. No Surrender of Others' Freedom.
529 |
530 | If conditions are imposed on you (whether by court order, agreement or
531 | otherwise) that contradict the conditions of this License, they do not
532 | excuse you from the conditions of this License. If you cannot convey a
533 | covered work so as to satisfy simultaneously your obligations under this
534 | License and any other pertinent obligations, then as a consequence you may
535 | not convey it at all. For example, if you agree to terms that obligate you
536 | to collect a royalty for further conveying from those to whom you convey
537 | the Program, the only way you could satisfy both those terms and this
538 | License would be to refrain entirely from conveying the Program.
539 |
540 | 13. Remote Network Interaction; Use with the GNU General Public License.
541 |
542 | Notwithstanding any other provision of this License, if you modify the
543 | Program, your modified version must prominently offer all users
544 | interacting with it remotely through a computer network (if your version
545 | supports such interaction) an opportunity to receive the Corresponding
546 | Source of your version by providing access to the Corresponding Source
547 | from a network server at no charge, through some standard or customary
548 | means of facilitating copying of software. This Corresponding Source
549 | shall include the Corresponding Source for any work covered by version 3
550 | of the GNU General Public License that is incorporated pursuant to the
551 | following paragraph.
552 |
553 | Notwithstanding any other provision of this License, you have
554 | permission to link or combine any covered work with a work licensed
555 | under version 3 of the GNU General Public License into a single
556 | combined work, and to convey the resulting work. The terms of this
557 | License will continue to apply to the part which is the covered work,
558 | but the work with which it is combined will remain governed by version
559 | 3 of the GNU General Public License.
560 |
561 | 14. Revised Versions of this License.
562 |
563 | The Free Software Foundation may publish revised and/or new versions of
564 | the GNU Affero General Public License from time to time. Such new versions
565 | will be similar in spirit to the present version, but may differ in detail to
566 | address new problems or concerns.
567 |
568 | Each version is given a distinguishing version number. If the
569 | Program specifies that a certain numbered version of the GNU Affero General
570 | Public License "or any later version" applies to it, you have the
571 | option of following the terms and conditions either of that numbered
572 | version or of any later version published by the Free Software
573 | Foundation. If the Program does not specify a version number of the
574 | GNU Affero General Public License, you may choose any version ever published
575 | by the Free Software Foundation.
576 |
577 | If the Program specifies that a proxy can decide which future
578 | versions of the GNU Affero General Public License can be used, that proxy's
579 | public statement of acceptance of a version permanently authorizes you
580 | to choose that version for the Program.
581 |
582 | Later license versions may give you additional or different
583 | permissions. However, no additional obligations are imposed on any
584 | author or copyright holder as a result of your choosing to follow a
585 | later version.
586 |
587 | 15. Disclaimer of Warranty.
588 |
589 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
590 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
591 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
592 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
593 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
594 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
595 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
596 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
597 |
598 | 16. Limitation of Liability.
599 |
600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
602 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
603 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
604 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
605 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
606 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
607 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
608 | SUCH DAMAGES.
609 |
610 | 17. Interpretation of Sections 15 and 16.
611 |
612 | If the disclaimer of warranty and limitation of liability provided
613 | above cannot be given local legal effect according to their terms,
614 | reviewing courts shall apply local law that most closely approximates
615 | an absolute waiver of all civil liability in connection with the
616 | Program, unless a warranty or assumption of liability accompanies a
617 | copy of the Program in return for a fee.
618 |
619 | END OF TERMS AND CONDITIONS
620 |
621 | How to Apply These Terms to Your New Programs
622 |
623 | If you develop a new program, and you want it to be of the greatest
624 | possible use to the public, the best way to achieve this is to make it
625 | free software which everyone can redistribute and change under these terms.
626 |
627 | To do so, attach the following notices to the program. It is safest
628 | to attach them to the start of each source file to most effectively
629 | state the exclusion of warranty; and each file should have at least
630 | the "copyright" line and a pointer to where the full notice is found.
631 |
632 |
633 | Copyright (C)
634 |
635 | This program is free software: you can redistribute it and/or modify
636 | it under the terms of the GNU Affero General Public License as published by
637 | the Free Software Foundation, either version 3 of the License, or
638 | (at your option) any later version.
639 |
640 | This program is distributed in the hope that it will be useful,
641 | but WITHOUT ANY WARRANTY; without even the implied warranty of
642 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
643 | GNU Affero General Public License for more details.
644 |
645 | You should have received a copy of the GNU Affero General Public License
646 | along with this program. If not, see .
647 |
648 | Also add information on how to contact you by electronic and paper mail.
649 |
650 | If your software can interact with users remotely through a computer
651 | network, you should also make sure that it provides a way for users to
652 | get its source. For example, if your program is a web application, its
653 | interface could display a "Source" link that leads users to an archive
654 | of the code. There are many ways you could offer source, and different
655 | solutions will be better for different programs; see section 13 for the
656 | specific requirements.
657 |
658 | You should also get your employer (if you work as a programmer) or school,
659 | if any, to sign a "copyright disclaimer" for the program, if necessary.
660 | For more information on this, and how to apply and follow the GNU AGPL, see
661 | .
662 |
--------------------------------------------------------------------------------