Matrix/main.go

87 lines
3.5 KiB
Go
Raw Permalink Normal View History

2020-09-28 20:37:02 +00:00
package main
import (
2020-10-11 21:11:30 +00:00
"crypto/tls"
2020-09-28 20:37:02 +00:00
"log"
"net/http"
2020-09-29 07:44:35 +00:00
"os"
2020-09-28 20:37:02 +00:00
2020-10-12 14:16:28 +00:00
"git.nutfactory.org/hoernschen/Matrix/config"
"git.nutfactory.org/hoernschen/Matrix/entities/device"
"git.nutfactory.org/hoernschen/Matrix/entities/event"
"git.nutfactory.org/hoernschen/Matrix/entities/general"
"git.nutfactory.org/hoernschen/Matrix/entities/room"
"git.nutfactory.org/hoernschen/Matrix/entities/user"
"git.nutfactory.org/hoernschen/Matrix/utils/database"
"git.nutfactory.org/hoernschen/Matrix/utils/router"
2020-09-28 20:37:02 +00:00
)
var keyPath = "./ssl.key"
var certPath = "./ssl.crt"
var routes = router.Routes{
2020-10-11 21:11:30 +00:00
2020-09-28 20:37:02 +00:00
// General
2020-10-11 21:11:30 +00:00
router.Route{"ResolveServerName", "GET", "/.well-known/matrix/server", general.ResolveServerName},
router.Route{"GetServerImplementation", "GET", "/_matrix/federation/v1/version", general.GetServerImplementation},
router.Route{"Reset", "GET", "/reset", general.Reset},
2020-10-17 10:07:39 +00:00
router.Route{"SetParams", "GET", "/setparams", general.SetParams},
2020-09-28 20:37:02 +00:00
// Keys
2020-10-11 21:11:30 +00:00
router.Route{"GetSigningKey", "GET", "/_matrix/key/v2/server/{keyId}", device.GetServerSigningKeyHandler},
router.Route{"GetSigningKey", "GET", "/_matrix/key/v2/server", device.GetServerSigningKeyHandler},
2020-09-28 20:37:02 +00:00
// Users
2020-10-11 21:11:30 +00:00
router.Route{"CheckUsernameAvailability", "GET", "/_matrix/client/r0/register/available", user.CheckUsernameAvailabilityHandler},
router.Route{"Register", "POST", "/_matrix/client/r0/register", user.RegisterHandler},
router.Route{"Login", "POST", "/_matrix/client/r0/login", user.LoginHandler},
router.Route{"Logout", "POST", "/_matrix/client/r0/logout", user.LogoutHandler},
2020-09-28 20:37:02 +00:00
// Rooms
2020-10-11 21:11:30 +00:00
router.Route{"CreateRoom", "POST", "/_matrix/client/r0/createRoom", room.CreateRoomHandler},
router.Route{"GetRoomMembers", "GET", "/_matrix/client/r0/rooms/{roomId}/members", room.GetRoomMemberHandler},
router.Route{"JoinRoomUser", "POST", "/_matrix/client/r0/rooms/{roomId}/join", room.JoinRoomUserHandler},
2020-09-28 20:37:02 +00:00
2020-10-11 21:11:30 +00:00
router.Route{"GetPrepInfoToJoin", "GET", "/_matrix/federation/v1/make_join/{roomId}/{userId}", room.GetPrepInfoToJoinHandler},
router.Route{"JoinRoomServer", "PUT", "/_matrix/federation/v2/send_join/{roomId}/{eventId}", room.JoinRoomServerHandler},
2020-09-28 20:37:02 +00:00
// Events
2020-10-11 21:11:30 +00:00
router.Route{"CreateEvent", "PUT", "/_matrix/client/r0/rooms/{roomId}/send/{eventType}/{txnId}", event.SendMessageHandler},
router.Route{"CreateStateEvent", "PUT", "/_matrix/client/r0/rooms/{roomId}/state/{eventType}/{stateKey}", event.CreateStateEventHandler},
router.Route{"GetEventUser", "GET", "/_matrix/client/r0/rooms/{roomId}/event/{eventId}", event.GetEventUserHandler},
router.Route{"GetStateEvent", "GET", "/_matrix/client/r0/rooms/{roomId}/state/{eventType}/{stateKey}", event.GetStateEventHandler},
2020-09-28 20:37:02 +00:00
2020-10-11 21:11:30 +00:00
router.Route{"SyncEventsServer", "PUT", "/_matrix/federation/v1/send/{txnId}", event.SyncEventsServerHandler},
router.Route{"Backfill", "GET", "/_matrix/federation/v1/backfill/{roomId}", event.BackfillHandler},
2020-09-28 20:37:02 +00:00
}
func main() {
2020-10-11 21:11:30 +00:00
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
config.Homeserver = "localhost"
config.Port = "80"
2020-10-12 14:16:28 +00:00
if len(os.Args) > 1 {
config.Homeserver = os.Args[1]
}
log.Printf("Start homeserver on name %s", config.Homeserver)
2020-10-11 21:11:30 +00:00
if err := device.InitServerSigningKey(); err != nil {
log.Fatal(err)
}
config.VerifyKeys = make(map[string]map[string][]byte)
2020-09-29 07:44:35 +00:00
os.Remove("sqlite.db")
2020-10-11 21:11:30 +00:00
if err := database.InitDB("sqlite.db"); err != nil {
log.Fatal(err)
}
defer database.DB.Close()
2020-09-28 20:37:02 +00:00
2020-10-17 10:07:39 +00:00
config.SetDefaultParams()
2020-09-28 20:37:02 +00:00
2020-10-11 21:11:30 +00:00
router := router.NewRouter(routes)
2020-09-28 20:37:02 +00:00
httpErr := http.ListenAndServeTLS(":443", certPath, keyPath, router)
if httpErr != nil {
log.Fatal(httpErr)
}
}