Skip to content

Commit 37e1bcb

Browse files
committed
add risky room expiry
1 parent 092d26a commit 37e1bcb

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

collab/main.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"os"
1111
"strconv"
1212
"sync"
13+
"time"
1314

1415
"github.com/gin-gonic/gin"
1516
"github.com/gorilla/websocket"
@@ -351,10 +352,25 @@ func handleMessages(
351352
Type: msgData.Type,
352353
UserID: msgData.UserID,
353354
}
355+
356+
extendExpiryTime(msgData.UserID, persistMappings)
354357
} else {
355358
log.Printf("Unknown message type: %s", msgData.Type)
356-
}
357359
}
360+
}
361+
}
362+
363+
func extendExpiryTime(userId string, persistMappings *verify.PersistMappings) {
364+
365+
ctx := context.Background()
366+
if err := persistMappings.Conn.Expire(ctx, userId, time.Minute * 10).Err(); err != nil {
367+
log.Println("Error extending room time on ping: ", err.Error())
368+
} else {
369+
370+
log.Printf("expiration reset for 10 minutes for user %s: ", userId)
371+
}
372+
373+
358374
}
359375

360376
type ClientWorkspace struct {

collab/verify/persistMappings.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,7 @@ func VerifyPersist(persistMappings *PersistMappings, roomID string, userID strin
3030
return false
3131
}
3232

33+
log.Printf("current roomID: %s, expected roomID: %s", data["roomId"], roomID)
34+
3335
return data["roomId"] == roomID
3436
}

collab/verify/roomMappings.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package verify
33
import (
44
"context"
55
"log"
6+
//"time"
67

78
redis "github.com/go-redis/redis/v8"
89
)
@@ -54,5 +55,13 @@ func VerifyRoomAndMoveToPersist(
5455
log.Printf("error sending room to persistent storage: %s", err.Error())
5556
}
5657

58+
/*
59+
if err := persistMappings.Conn.Expire(ctx, userId, 20 * time.Second).Err(); err != nil {
60+
log.Printf("error setting expiration for persisting room storage: %s", err.Error())
61+
} else {
62+
log.Printf("expiration set for 10 minutes for user %s: ", userId)
63+
64+
}
65+
*/
5766
return true
5867
}

peerprep/components/questionpage/CollabEditor.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,9 @@ export default function CollabEditor({
276276
clearInterval(interval);
277277
clearInterval(disconnectCheckInterval);
278278
};
279-
}, [notifyRoomOfConnection, PING_INTERVAL_MILLISECONDS, connected, socket]);
279+
}, [
280+
notifyRoomOfConnection, PING_INTERVAL_MILLISECONDS, connected, socket
281+
]);
280282

281283
const handleCloseConnection = () => {
282284
const confirmClose = confirm(

0 commit comments

Comments
 (0)