From 4b9d75c9c998273ef489e3ebc619f210fa24c8a5 Mon Sep 17 00:00:00 2001 From: Lucien Greathouse Date: Sun, 22 Apr 2018 02:49:40 -0700 Subject: [PATCH] Pick random serve port on [10000, 40000) instead of always using 8000 --- server/src/project.rs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/server/src/project.rs b/server/src/project.rs index 759e3583..f220b616 100644 --- a/server/src/project.rs +++ b/server/src/project.rs @@ -4,6 +4,8 @@ use std::fs::{self, File}; use std::io::{Read, Write}; use std::path::{Path, PathBuf}; +use rand::{self, Rng}; + use serde_json; pub static PROJECT_FILENAME: &'static str = "rojo.json"; @@ -82,14 +84,6 @@ pub struct Project { } impl Project { - /// Creates a new empty Project object with the given name. - pub fn new>(name: T) -> Project { - Project { - name: name.into(), - ..Default::default() - } - } - /// Initializes a new project inside the given folder path. pub fn init>(location: T) -> Result { let location = location.as_ref(); @@ -113,8 +107,15 @@ impl Project { None => "new-project".to_string(), }; + // Generate a random port to run the server on. + let serve_port = rand::thread_rng().gen_range(10000, 40000); + // Configure the project with all of the values we know so far. - let project = Project::new(name); + let project = Project { + name, + serve_port, + partitions: HashMap::new(), + }; let serialized = serde_json::to_string_pretty(&project).unwrap(); match file.write(serialized.as_bytes()) {