Skip to content

Commit def65aa

Browse files
committed
Add broadcast port, rename host_port to telnet_port
1 parent a9d1a21 commit def65aa

6 files changed

Lines changed: 66 additions & 25 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
alter table stations rename column host_port to telnet_port;
2+
alter table stations add column broadcast_port text not null default '';
3+
4+
---- create above / drop below ----
5+
6+
alter table stations drop column broadcast_port;
7+
alter table stations rename column telnet_port to host_port;

gap/db/models.go

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gap/db/query.sql

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,11 @@ insert into stations(station_id, slug, user_id, active) values($1, $2, $3, $4) r
3737
-- name: SetStationCurrentTrack :exec
3838
update stations set current_track_id = $1 where station_id = $2;
3939

40-
-- name: SetStationHostPort :exec
41-
update stations set host_port = $1 where station_id = $2;
40+
-- name: SetStationTelnetPort :exec
41+
update stations set telnet_port = $1 where station_id = $2;
42+
43+
-- name: SetStationBroadcastPort :exec
44+
update stations set broadcast_port = $1 where station_id = $2;
4245

4346
-- name: StationCurrentTrack :one
4447
select tracks.* from stations join tracks on stations.current_track_id = tracks.track_id where stations.station_id = $1;

gap/db/query.sql.go

Lines changed: 22 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gap/db/schema.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,8 @@ CREATE TABLE public.stations (
264264
background_image_url text DEFAULT ''::text NOT NULL,
265265
user_id text NOT NULL,
266266
is_public boolean DEFAULT false NOT NULL,
267-
host_port text DEFAULT ''::text NOT NULL
267+
telnet_port text DEFAULT ''::text NOT NULL,
268+
broadcast_port text DEFAULT ''::text NOT NULL
268269
);
269270

270271

gap/internal/server/routes.go

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -475,20 +475,26 @@ func (s *Server) startLiq(w http.ResponseWriter, r *http.Request) {
475475
AttachStderr: true,
476476
ExposedPorts: nat.PortSet{
477477
"1234/tcp": struct{}{},
478+
"8000/tcp": struct{}{},
478479
},
479480
},
480481
&container.HostConfig{
481482
RestartPolicy: container.RestartPolicy{
482483
Name: "always",
483484
MaximumRetryCount: 0,
484485
},
485-
// use random port since we have multiple containers running
486+
// use random host ports since we have multiple containers running
486487
PortBindings: nat.PortMap{
487488
"1234/tcp": []nat.PortBinding{
488489
{
489490
HostIP: "0.0.0.0",
490491
},
491492
},
493+
"8000/tcp": []nat.PortBinding{
494+
{
495+
HostIP: "0.0.0.0",
496+
},
497+
},
492498
},
493499
},
494500
&network.NetworkingConfig{
@@ -517,18 +523,29 @@ func (s *Server) startLiq(w http.ResponseWriter, r *http.Request) {
517523
return
518524
}
519525
for containerPort, bindings := range resp.NetworkSettings.Ports {
520-
fmt.Println("containerPort", containerPort)
521-
if containerPort.Port() == "1234" {
526+
if len(bindings) == 1 {
522527
var hostPort string
523-
if len(bindings) == 1 {
524-
hostPort = bindings[0].HostPort
525-
}
526-
err := s.db.Q().SetStationHostPort(ctx, hostPort, station.StationID)
527-
if err != nil {
528-
http.Error(w, err.Error(), http.StatusInternalServerError)
529-
return
528+
hostPort = bindings[0].HostPort
529+
fmt.Println("containerPort", containerPort, "hostPort", hostPort)
530+
switch containerPort.Port() {
531+
case "1234":
532+
err := s.db.Q().SetStationTelnetPort(ctx, hostPort, station.StationID)
533+
if err != nil {
534+
http.Error(w, err.Error(), http.StatusInternalServerError)
535+
return
536+
}
537+
fmt.Printf("station %s host port=%s\n", station.Slug, hostPort)
538+
case "8000":
539+
err := s.db.Q().SetStationBroadcastPort(ctx, hostPort, station.StationID)
540+
if err != nil {
541+
http.Error(w, err.Error(), http.StatusInternalServerError)
542+
return
543+
}
544+
fmt.Printf("station %s host port=%s\n", station.Slug, hostPort)
530545
}
531-
fmt.Printf("station %s host port=%s\n", station.Slug, hostPort)
546+
} else {
547+
http.Error(w, "weird, len(bindings)!=1", http.StatusInternalServerError)
548+
return
532549
}
533550
}
534551

0 commit comments

Comments
 (0)