From 9ed609b9df7ea92fd47ff567b2cede3e801fc638 Mon Sep 17 00:00:00 2001 From: Mark Haines Date: Tue, 26 Sep 2017 12:53:30 +0100 Subject: [PATCH] Pass requests made by remote servers for media to the media API (#263) --- INSTALL.md | 83 ++++++++++--------- .../dendrite/cmd/federation-api-proxy/main.go | 14 ++++ 2 files changed, 56 insertions(+), 41 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 249064a62..f562cd492 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -108,47 +108,47 @@ The following contains scripts which will run all the required processes in orde ``` - /media +---------------------------+ - +--------->| dendrite-media-api-server | - | +---------------------------+ - | :7774 - | - | - |/directory+----------------------------------+ - +--------->| dendrite-public-rooms-api-server |<========++ - | +----------------------------------+ || - | :7775 | || - | +<-----------+ || - | | || - | /sync +--------------------------+ || - +--------->| dendrite-sync-api-server |<================++ - | | +--------------------------+ || - | | :7773 | ^^ || -Matrix +------------------+ | | | || client_data || -Clients --->| client-api-proxy |---+ +<-----------+ ++=============++ || - +------------------+ | | || || - :8008 | CS API +----------------------------+ || || - +--------->| dendrite-client-api-server |==++ || - | +----------------------------+ || - | :7771 | || - | | || - +<-----------+ || - | || - | || - | +----------------------+ room_event || - +---------->| dendrite-room-server |===============++ - | +----------------------+ || - | :7770 || - | ++==========================++ - +<------------+ || - | | VV - | +-----------------------------------+ Matrix - | | dendrite-federation-sender-server |------------> Servers - | +-----------------------------------+ - | :7776 - | - +<-----------+ - | + /media +---------------------------+ + +----------->+------------->| dendrite-media-api-server | + ^ ^ +---------------------------+ + | | :7774 + | | + | | + | | /directory +----------------------------------+ + | | +--------->| dendrite-public-rooms-api-server |<========++ + | | | +----------------------------------+ || + | | | :7775 | || + | | | +<-----------+ || + | | | | || + | | | /sync +--------------------------+ || + | | +--------->| dendrite-sync-api-server |<================++ + | | | | +--------------------------+ || + | | | | :7773 | ^^ || +Matrix +------------------+ | | | | || client_data || +Clients --->| client-api-proxy |-------+ +<-----------+ ++=============++ || + +------------------+ | | | || || + :8008 | | CS API +----------------------------+ || || + | +--------->| dendrite-client-api-server |==++ || + | | +----------------------------+ || + | | :7771 | || + | | | || + | +<-----------+ || + | | || + | | || + | | +----------------------+ room_event || + | +---------->| dendrite-room-server |===============++ + | | +----------------------+ || + | | :7770 || + | | ++==========================++ + | +<------------+ || + | | | VV + | | +-----------------------------------+ Matrix + | | | dendrite-federation-sender-server |------------> Servers + | | +-----------------------------------+ + | | :7776 + | | + +---------->+ +<-----------+ + | | Matrix +----------------------+ SS API +--------------------------------+ Servers --->| federation-api-proxy |--------->| dendrite-federation-api-server | +----------------------+ +--------------------------------+ @@ -222,6 +222,7 @@ This is what Matrix servers will talk to. This is only required if you want to s ./bin/federation-api-proxy \ --bind-address ":8448" \ --federation-api-url "http://localhost:7772" \ +--media-api-server-url "http://localhost:7774" \ ``` ### Run a federation api server diff --git a/src/github.com/matrix-org/dendrite/cmd/federation-api-proxy/main.go b/src/github.com/matrix-org/dendrite/cmd/federation-api-proxy/main.go index ed0aed722..0eacbfa50 100644 --- a/src/github.com/matrix-org/dendrite/cmd/federation-api-proxy/main.go +++ b/src/github.com/matrix-org/dendrite/cmd/federation-api-proxy/main.go @@ -48,6 +48,7 @@ Arguments: var ( federationAPIURL = flag.String("federation-api-url", "", "The base URL of the listening 'dendrite-federation-api-server' process. E.g. 'http://localhost:4200'") + mediaAPIURL = flag.String("media-api-server-url", "", "The base URL of the listening 'dendrite-media-api-server' process. E.g. 'http://localhost:7779'") bindAddress = flag.String("bind-address", ":8448", "The listening port for the proxy.") certFile = flag.String("tls-cert", "server.crt", "The PEM formatted X509 certificate to use for TLS") keyFile = flag.String("tls-key", "server.key", "The PEM private key to use for TLS") @@ -104,11 +105,23 @@ func main() { os.Exit(1) } + if *mediaAPIURL == "" { + flag.Usage() + fmt.Fprintln(os.Stderr, "no --media-api-server-url specified.") + os.Exit(1) + } + federationProxy, err := makeProxy(*federationAPIURL) if err != nil { panic(err) } + mediaProxy, err := makeProxy(*mediaAPIURL) + if err != nil { + panic(err) + } + + http.Handle("/_matrix/media/v1/", mediaProxy) http.Handle("/", federationProxy) srv := &http.Server{ @@ -118,6 +131,7 @@ func main() { } fmt.Println("Proxying requests to:") + fmt.Println(" /_matrix/media/v1 => ", *mediaAPIURL+"/api/_matrix/media/v1") fmt.Println(" /* => ", *federationAPIURL+"/api/*") fmt.Println("Listening on ", *bindAddress) panic(srv.ListenAndServeTLS(*certFile, *keyFile))