Expose unix timestamp on /listeners
continuous-integration/drone/push Build is passing Details

This commit is contained in:
DataHoarder 2022-08-23 21:47:09 +02:00
parent 78377bc860
commit eec79cb3ab
Signed by: DataHoarder
SSH Key Fingerprint: SHA256:OLTRf6Fl87G52SiR7sWLGNzlJt4WOX+tfI2yxo0z7xk
3 changed files with 8 additions and 2 deletions

View File

@ -113,10 +113,12 @@ Drops the listener connection with `listener_id` specified as a parameter.
```
### `CHANGED` GET /listeners
Same as kawa's, but `identifier` is added to each listener entry.
Same as kawa's, but `identifier` and `start` is added to each listener entry.
The listener `identifier` is generated based on user connection address, port, user-agent and mount.
The `start` field denotes the unix time this listener connected.
Additionally, a `x-listener-identifier` header is exposed to mount response.
#### Response
@ -126,6 +128,7 @@ Additionally, a `x-listener-identifier` header is exposed to mount response.
"identifier": "641df131cb52f8f6381d9946cccb822e",
"mount": "stream.flac",
"path": "/stream.flac",
"start": 1661283903,
"headers": [
{
"name": "User-Agent",

View File

@ -25,6 +25,7 @@ type ListenerInformation struct {
Identifier string `json:"identifier"`
Mount string `json:"mount"`
Path string `json:"path"`
Start int64 `json:"start"`
Headers []HeaderEntry `json:"headers"`
}

View File

@ -949,7 +949,8 @@ func (q *Queue) HandleRadioRequest(writer http.ResponseWriter, request *http.Req
wgClient.Add(1)
hashSum := sha256.Sum256([]byte(fmt.Sprintf("%s-%s-%s-%s", request.RequestURI, request.RemoteAddr, request.Proto, request.Header.Get("user-agent"))))
startStamp := time.Now().Unix()
hashSum := sha256.Sum256([]byte(fmt.Sprintf("%s-%s-%s-%s-%d", request.RequestURI, request.RemoteAddr, request.Proto, request.Header.Get("user-agent"), startStamp)))
listenerIdentifier := hex.EncodeToString(hashSum[16:])
writer.Header().Set("x-listener-identifier", listenerIdentifier)
@ -960,6 +961,7 @@ func (q *Queue) HandleRadioRequest(writer http.ResponseWriter, request *http.Req
Mount: mount.Mount,
Path: uriPath,
Headers: headers,
Start: startStamp,
},
Start: func(packets []packetizer.Packet) error {
log.Printf("adding %s client to stream %s (%s, %s, agent \"%s\", buffer %.2f seconds)\n", listenerIdentifier, mount.Mount, request.RemoteAddr, request.Proto, request.Header.Get("user-agent"), float64(sampleBufferLimit)/float64(mount.SampleRate))