Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
webapp-lib
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CS-214
ul2024
webapp-lib
Commits
fe0dadbb
Commit
fe0dadbb
authored
5 months ago
by
Clément Pit-Claudel
Browse files
Options
Downloads
Patches
Plain Diff
server: Refactor wordlist loading
parent
98ce7952
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!38
Customizable homepage + automatic reconnection
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
jvm/src/main/scala/cs214/webapp/server/web/WebServer.scala
+13
-10
13 additions, 10 deletions
jvm/src/main/scala/cs214/webapp/server/web/WebServer.scala
with
13 additions
and
10 deletions
jvm/src/main/scala/cs214/webapp/server/web/WebServer.scala
+
13
−
10
View file @
fe0dadbb
...
...
@@ -4,18 +4,22 @@ package web
import
scala.collection.
{
concurrent
,
mutable
}
import
scala.util.
{
Failure
,
Success
,
Try
}
import
scala.io.
{
Source
}
import
cask.endpoints.WsChannelActor
private
def
withResource
[
T
](
fname
:
String
)(
body
:
Option
[
Source
]
=>
T
)
=
Option
(
this
.
getClass
.
getResourceAsStream
(
f
"/$fname"
))
match
case
Some
(
stream
)
=>
try
body
(
Some
(
Source
.
fromInputStream
(
stream
)(
scala
.
io
.
Codec
.
UTF8
)))
finally
stream
.
close
()
case
None
=>
body
(
None
)
private
case
class
Wordlist
(
fname
:
String
)
:
val
words:
Seq
[
String
]
=
import
scala.io.
{
Source
,
Codec
}
val
wordstream
=
Option
(
this
.
getClass
.
getResourceAsStream
(
f
"/$fname"
))
.
getOrElse
(
sys
.
error
(
f
"File not found: $fname"
))
try
Source
.
fromInputStream
(
wordstream
)(
Codec
.
UTF8
)
.
getLines
().
map
(
_
.
split
(
"\t"
).
last
).
to
(
Vector
)
finally
wordstream
.
close
()
withResource
(
fname
)
:
src
=>
src
.
getOrElse
(
sys
.
error
(
f
"File not found: $fname"
))
.
getLines
().
map
(
_
.
split
(
"\t"
).
last
).
to
(
Seq
)
def
randomWord
:
String
=
import
scala.util.Random
...
...
@@ -27,9 +31,8 @@ class TooManyInstances extends Exception("Too many instances.")
object
WebServer
:
val
MAX_INSTANCES
=
64000
private
val
instanceIdsFileName
=
"eff_short_wordlist_1.txt"
// Where to find the list of possible instance ids
private
val
instanceIdLength
=
4
// How many words do we concatenate for the instance id
private
val
instanceIdWords
=
Wordlist
(
instanceIdsFileName
)
private
val
instanceIdWords
=
Wordlist
(
"eff_short_wordlist_1.txt"
)
private
[
web
]
val
debug
=
false
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment