86 lines
3.5 KiB
Go
86 lines
3.5 KiB
Go
package main
|
|
|
|
import (
|
|
"crypto/tls"
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
|
|
"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"
|
|
)
|
|
|
|
var keyPath = "./ssl.key"
|
|
var certPath = "./ssl.crt"
|
|
|
|
var routes = router.Routes{
|
|
|
|
// General
|
|
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},
|
|
router.Route{"SetParams", "GET", "/setparams", general.SetParams},
|
|
|
|
// Keys
|
|
router.Route{"GetSigningKey", "GET", "/_matrix/key/v2/server/{keyId}", device.GetServerSigningKeyHandler},
|
|
router.Route{"GetSigningKey", "GET", "/_matrix/key/v2/server", device.GetServerSigningKeyHandler},
|
|
|
|
// Users
|
|
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},
|
|
|
|
// Rooms
|
|
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},
|
|
|
|
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},
|
|
|
|
// Events
|
|
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},
|
|
|
|
router.Route{"SyncEventsServer", "PUT", "/_matrix/federation/v1/send/{txnId}", event.SyncEventsServerHandler},
|
|
router.Route{"Backfill", "GET", "/_matrix/federation/v1/backfill/{roomId}", event.BackfillHandler},
|
|
}
|
|
|
|
func main() {
|
|
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
|
|
config.Homeserver = "localhost"
|
|
config.Port = "80"
|
|
if len(os.Args) > 1 {
|
|
config.Homeserver = os.Args[1]
|
|
}
|
|
log.Printf("Start homeserver on name %s", config.Homeserver)
|
|
|
|
if err := device.InitServerSigningKey(); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
config.VerifyKeys = make(map[string]map[string][]byte)
|
|
os.Remove("sqlite.db")
|
|
|
|
if err := database.InitDB("sqlite.db"); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
defer database.DB.Close()
|
|
|
|
config.SetDefaultParams()
|
|
|
|
router := router.NewRouter(routes)
|
|
|
|
httpErr := http.ListenAndServeTLS(":443", certPath, keyPath, router)
|
|
if httpErr != nil {
|
|
log.Fatal(httpErr)
|
|
}
|
|
}
|