Skip to content

Commit

Permalink
proxy: work on the proxy actually being functional
Browse files Browse the repository at this point in the history
streamer: fixed a bug where a icecast connection failure caused it
to skip the playing song.
  • Loading branch information
Wessie committed Mar 8, 2024
1 parent 4c464d7 commit 315e031
Show file tree
Hide file tree
Showing 10 changed files with 398 additions and 113 deletions.
6 changes: 4 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ var defaultConfig = config{
Fallback: "https://relay0.r-a-d.io/main.mp3",
},
Proxy: proxy{
Addr: ":1337",
Addr: ":1337",
MasterServer: "http://source:[email protected]:8000",
},
Telemetry: telemetry{
Use: false,
Expand Down Expand Up @@ -109,7 +110,8 @@ type config struct {
}

type proxy struct {
Addr string
Addr string
MasterServer string
}

type telemetry struct {
Expand Down
3 changes: 1 addition & 2 deletions jobs/listenlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package jobs
import (
"context"

radio "github.com/R-a-dio/valkyrie"
"github.com/R-a-dio/valkyrie/config"
"github.com/R-a-dio/valkyrie/storage"
"github.com/R-a-dio/valkyrie/util"
Expand All @@ -19,7 +18,7 @@ func ExecuteListenerLog(ctx context.Context, cfg config.Config) error {

m := cfg.Conf().Manager.Client()

status, err := util.OneOff[radio.Status](ctx, m.CurrentStatus)
status, err := util.OneOff(ctx, m.CurrentStatus)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion proxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func Execute(ctx context.Context, cfg config.Config) error {
// get our configuration
addr := cfg.Conf().Proxy.Addr

srv, err := NewServer(ctx, m, storage)
srv, err := NewServer(ctx, cfg, m, storage)
if err != nil {
return errors.E(op, err)
}
Expand Down
32 changes: 25 additions & 7 deletions proxy/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,21 @@ package proxy

import (
"context"
"net/url"

"github.com/R-a-dio/valkyrie/config"
"github.com/R-a-dio/valkyrie/errors"
"github.com/rs/zerolog"
)

func createMountURL(master url.URL, mount string) *url.URL {
master.Path = mount
return &master
}

type ProxyManager struct {
masterServerURL *url.URL

newSource chan *SourceClient
newMetadata chan *Metadata

Expand All @@ -15,14 +25,21 @@ type ProxyManager struct {
Mounts map[string]*Mount
}

func NewProxyManager() *ProxyManager {
func NewProxyManager(cfg config.Config) (*ProxyManager, error) {
const op errors.Op = "proxy.NewProxyManager"

uri, err := url.Parse(cfg.Conf().Proxy.MasterServer)
if err != nil {
return nil, errors.E(op, err)
}
m := &ProxyManager{
newSource: make(chan *SourceClient),
newMetadata: make(chan *Metadata),
metaStore: make(map[Identifier]*Metadata),
Mounts: make(map[string]*Mount),
masterServerURL: uri,
newSource: make(chan *SourceClient),
newMetadata: make(chan *Metadata),
metaStore: make(map[Identifier]*Metadata),
Mounts: make(map[string]*Mount),
}
return m
return m, nil
}

func (pm *ProxyManager) Run(ctx context.Context) {
Expand All @@ -31,11 +48,12 @@ func (pm *ProxyManager) Run(ctx context.Context) {
for {
select {
case source := <-pm.newSource:
// TODO: check if all source clients have the same content-type
m, ok := pm.Mounts[source.MountName]
if !ok {
// no mount exists yet, create one
logger.Info().Str("mount", source.MountName).Msg("create mount")
m = NewMount(ctx, nil)
m = NewMount(ctx, createMountURL(*pm.masterServerURL, source.MountName), source.ContentType)
pm.Mounts[source.MountName] = m
}

Expand Down
Loading

0 comments on commit 315e031

Please sign in to comment.