mirror of
https://github.com/status-im/status-go.git
synced 2025-01-09 22:26:30 +00:00
7f149f93c1
* Added function to get preffered network IP Also done some refactor work oon server package to make a lot more reusable * Added server.Option and simplified handler funcs * Added serial number deterministically generated from pk * Debugging TLS server connection * Implemented configurable server ip When accessing over the network the server needs to listen on the network port and not localhost or 127.0.0.1 . Also the cert can now have a dedicated IP * Refactor of URL funcs to use the url package * Removed redundant Options pattern in favour of config param * Added full server test using GetOutboundIP * Remove references and usage of Server.port The application does not need to set the port, we rely on the net.Listener to pick a port. * Version bump * Added ToECDSA func and improved cert testing * Added error check in test * Split Server types, embedding raw Server funcs into specialised server types * localhost * Implemented DNS and IP based cert gen ios doesn't allow for restricted ip addresses to be used in a valid tls cert * Replace listener handling with original port store Also added handlers as a parameter of the Server
76 lines
1.5 KiB
Go
76 lines
1.5 KiB
Go
package server
|
|
|
|
import (
|
|
"database/sql"
|
|
"net/url"
|
|
|
|
"github.com/status-im/status-go/ipfs"
|
|
)
|
|
|
|
type MediaServer struct {
|
|
Server
|
|
|
|
db *sql.DB
|
|
downloader *ipfs.Downloader
|
|
}
|
|
|
|
// NewMediaServer returns a *MediaServer
|
|
func NewMediaServer(db *sql.DB, downloader *ipfs.Downloader) (*MediaServer, error) {
|
|
err := generateTLSCert()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
s := &MediaServer{
|
|
Server: NewServer(globalCertificate, localhost),
|
|
db: db,
|
|
downloader: downloader,
|
|
}
|
|
s.SetHandlers(HandlerPatternMap{
|
|
imagesPath: handleImage(s.db, s.logger),
|
|
audioPath: handleAudio(s.db, s.logger),
|
|
identiconsPath: handleIdenticon(s.logger),
|
|
ipfsPath: handleIPFS(s.downloader, s.logger),
|
|
})
|
|
|
|
return s, nil
|
|
}
|
|
|
|
func (s *MediaServer) MakeImageServerURL() string {
|
|
u := s.MakeBaseURL()
|
|
u.Path = basePath + "/"
|
|
return u.String()
|
|
}
|
|
|
|
func (s *MediaServer) MakeIdenticonURL(from string) string {
|
|
u := s.MakeBaseURL()
|
|
u.Path = identiconsPath
|
|
u.RawQuery = url.Values{"publicKey": {from}}.Encode()
|
|
|
|
return u.String()
|
|
}
|
|
|
|
func (s *MediaServer) MakeImageURL(id string) string {
|
|
u := s.MakeBaseURL()
|
|
u.Path = imagesPath
|
|
u.RawQuery = url.Values{"messageId": {id}}.Encode()
|
|
|
|
return u.String()
|
|
}
|
|
|
|
func (s *MediaServer) MakeAudioURL(id string) string {
|
|
u := s.MakeBaseURL()
|
|
u.Path = audioPath
|
|
u.RawQuery = url.Values{"messageId": {id}}.Encode()
|
|
|
|
return u.String()
|
|
}
|
|
|
|
func (s *MediaServer) MakeStickerURL(stickerHash string) string {
|
|
u := s.MakeBaseURL()
|
|
u.Path = ipfsPath
|
|
u.RawQuery = url.Values{"hash": {stickerHash}}.Encode()
|
|
|
|
return u.String()
|
|
}
|