Browse Source

Remote media server support

Closes #1
master
HimbeerserverDE 6 months ago
parent
commit
90c4865b24
No known key found for this signature in database
GPG Key ID: 1A651504791E6A8B
  1. 29
      content.go
  2. 8
      process.go

29
content.go

@ -50,7 +50,8 @@ type contentConn struct {
nodeDefs []mt.NodeDef
media []mediaFile
media []mediaFile
remotes []string
}
func (cc *contentConn) state() clientState {
@ -251,6 +252,11 @@ func handleContent(cc *contentConn) {
})
}
cc.remotes = strings.Split(cmd.URL, ",")
for k, v := range cc.remotes {
cc.remotes[k] = strings.TrimSpace(v)
}
cc.SendCmd(&mt.ToSrvReqMedia{Filenames: filenames})
case *mt.ToCltMedia:
for _, f := range cmd.Files {
@ -468,7 +474,25 @@ func muxMedia(conns []*contentConn) []mediaFile {
return media
}
func muxContent(userName string) (itemDefs []mt.ItemDef, aliases []struct{ Alias, Orig string }, nodeDefs []mt.NodeDef, p0Map param0Map, p0SrvMap param0SrvMap, media []mediaFile, err error) {
func muxRemotes(conns []*contentConn) []string {
remotes := make(map[string]struct{})
for _, cc := range conns {
<-cc.done()
for _, v := range cc.remotes {
remotes[v] = struct{}{}
}
}
urls := make([]string, 0, len(remotes))
for remote := range remotes {
urls = append(urls, remote)
}
return urls
}
func muxContent(userName string) (itemDefs []mt.ItemDef, aliases []struct{ Alias, Orig string }, nodeDefs []mt.NodeDef, p0Map param0Map, p0SrvMap param0SrvMap, media []mediaFile, remotes []string, err error) {
var conns []*contentConn
for _, srv := range Conf().Servers {
var addr *net.UDPAddr
@ -496,6 +520,7 @@ func muxContent(userName string) (itemDefs []mt.ItemDef, aliases []struct{ Alias
itemDefs, aliases = muxItemDefs(conns)
nodeDefs, p0Map, p0SrvMap = muxNodeDefs(conns)
media = muxMedia(conns)
remotes = muxRemotes(conns)
return
}

8
process.go

@ -349,8 +349,9 @@ func (cc *ClientConn) process(pkt mt.Pkt) {
return
case *mt.ToSrvInit2:
var remotes []string
var err error
cc.itemDefs, cc.aliases, cc.nodeDefs, cc.p0Map, cc.p0SrvMap, cc.media, err = muxContent(cc.Name())
cc.itemDefs, cc.aliases, cc.nodeDefs, cc.p0Map, cc.p0SrvMap, cc.media, remotes, err = muxContent(cc.Name())
if err != nil {
cc.Log("<-", err.Error())
cc.Kick("Content multiplexing failed.")
@ -374,7 +375,10 @@ func (cc *ClientConn) process(pkt mt.Pkt) {
})
}
cc.SendCmd(&mt.ToCltAnnounceMedia{Files: files})
cc.SendCmd(&mt.ToCltAnnounceMedia{
Files: files,
URL: strings.Join(remotes, ","),
})
cc.lang = cmd.Lang
var csmrf mt.CSMRestrictionFlags

Loading…
Cancel
Save