/// <summary> /// Initializes a new instance of the <see cref="Station"/> class. /// Can I have a new Station? /// </summary> /// <param name="ui"> /// A reference to the UI. /// </param> /// <param name="port"> /// The port the station should listen to. Defaults to 62000. /// </param> /// <param name="dbPrefix"> /// The prefix of the voter database prefix. /// </param> public Station(IDvlUi ui, bool local = false, int port = 62000, string dbPrefix = "Voters") { Contract.Requires(ui != null); Contract.Requires(dbPrefix != null); Peers = new SortedDictionary <IPEndPoint, AsymmetricKey>(new IPEndPointComparer()); PeerStatuses = new SortedDictionary <IPEndPoint, StationStatus>(new IPEndPointComparer()); ElectionInProgress = false; if (local) { Communicator = new LocalhostCommunicator(this); } else { Communicator = new InternetCommunicator(this); } Address = Communicator.GetLocalEndPoint(port); _dbPrefix = dbPrefix; UI = ui; Crypto = new Crypto(); StartListening(); }
/// <summary> /// Can I have a new Station that is the manager? /// </summary> /// <param name="ui">A reference to the UI.</param> /// <param name="keyPath">The patch to the key-file.</param> /// <param name="masterPassword">The masterpassword known only by the election secretary.</param> /// <param name="port">The network port the station is communicating over. Defaults to 62000.</param> /// <param name="voterDbName">The name of the voter database. Defaults to Voters.sqlite.</param> /// <param name="logName">The name of the logging database. Defaults to Log.sqlite.</param> public Station(IDvlUi ui, string keyPath, string masterPassword, int port = 62000, string voterDbName = "Voters.sqlite", string logName = "Log.sqlite") : this(ui, new AsymmetricKey(Bytes.FromFile(keyPath).ToKey()), masterPassword, port, voterDbName, logName) { Contract.Requires(ui != null); Contract.Requires(keyPath != null); Contract.Requires(File.Exists(keyPath)); Contract.Requires(voterDbName != null); Contract.Requires(logName != null); }
/// <summary> /// Can I have a new Station? /// </summary> /// <param name="ui">A reference to the UI.</param> /// <param name="port">The port the station should listen to. Defaults to 62000.</param> /// <param name="databaseFile">The name of the database file.</param> public Station(IDvlUi ui, int port = 62000, string databaseFile = "Voters.sqlite") { Contract.Requires(ui != null); Contract.Requires(databaseFile != null); Peers = new SortedDictionary <IPEndPoint, AsymmetricKey>(new IPEndPointComparer()); ElectionInProgress = false; Address = new IPEndPoint(Dns.GetHostEntry(Dns.GetHostName()).AddressList.First(ip => ip.AddressFamily == AddressFamily.InterNetwork), port); Database = new SqLiteDatabase(this, databaseFile); Communicator = new Communicator(this); UI = ui; Crypto = new Crypto(); StartListening(); }
/// <summary> /// Can I have a new Station that is the manager? /// </summary> /// <param name="ui">A reference to the UI.</param> /// <param name="voterDataEncryptionKey">The AsymmetricKey used for encrypting the data at this election venue.</param> /// <param name="masterpassword">The masterpassword known only by the election secretary.</param> /// <param name="port">The network port the station is communicating over. Defaults to 62000.</param> /// <param name="voterDbName">The name of the voter database. Defaults to Voters.sqlite.</param> /// <param name="logName">The name of the logging database. Defaults to Log.sqlite.</param> public Station(IDvlUi ui, AsymmetricKey voterDataEncryptionKey, string masterpassword, int port = 62000, string voterDbName = "Voters.sqlite", string logName = "Log.sqlite") : this(ui, port, voterDbName) { Contract.Requires(ui != null); Contract.Requires(masterpassword != null); Contract.Requires(voterDbName != null); Contract.Requires(logName != null); Crypto = new Crypto(voterDataEncryptionKey); MasterPassword = Crypto.Hash(Bytes.From("_½æøåÆÅا.^\\,QBsa(/YHh*^#3£()cZ?\\}`|`´ '*jJxCvZ;;;<><aQ\\ ><" + masterpassword)); Logger = new Logger(this, logName); Manager = Address; Logger.Log("Manager initialized", Level.Info); }
/// <summary> /// Initializes a new instance of the <see cref="Station"/> class. /// Can I have a new Station that is the manager? /// </summary> /// <param name="ui"> /// A reference to the UI. /// </param> /// <param name="keyPath"> /// The path to the key-file. /// </param> /// <param name="masterPassword"> /// The master password known only by the election secretary. /// </param> /// <param name="port"> /// The network port the station is communicating over. Defaults to 62000. /// </param> /// <param name="dbPrefix"> /// The prefix of the voter database prefix. Defaults to Voters. /// </param> /// <param name="logPrefix"> /// The prefix of the logging database prefix. Defaults to Log. /// </param> public Station(IDvlUi ui, string keyPath, string masterPassword, bool local, int port = 62000, string dbPrefix = "Voters", string logPrefix = "Log") : this(ui, new AsymmetricKey(Bytes.FromFile(keyPath).ToKey()), masterPassword, local, port, dbPrefix, logPrefix) { Contract.Requires(ui != null); Contract.Requires(keyPath != null); Contract.Requires(File.Exists(keyPath)); Contract.Requires(dbPrefix != null); Contract.Requires(logPrefix != null); }
/// <summary> /// Initializes a new instance of the <see cref="Station"/> class. /// Can I have a new Station that is the manager? /// </summary> /// <param name="ui"> /// A reference to the UI. /// </param> /// <param name="voterDataEncryptionKey"> /// The AsymmetricKey used for encrypting the data at this election venue. /// </param> /// <param name="masterPassword"> /// The master password known only by the election secretary. /// </param> /// <param name="port"> /// The network port the station is communicating over. Defaults to 62000. /// </param> /// <param name="dbPrefix"> /// The prefix of the voter database prefix. Defaults to Voters. /// </param> /// <param name="logPrefix"> /// The prefix of the logging database prefix. Defaults to Log. /// </param> public Station(IDvlUi ui, AsymmetricKey voterDataEncryptionKey, string masterPassword, bool local = false, int port = 62000, string dbPrefix = "Voters", string logPrefix = "Log") : this(ui, local, port, dbPrefix) { Contract.Requires(ui != null); Contract.Requires(masterPassword != null); Contract.Requires(dbPrefix != null); Contract.Requires(logPrefix != null); Crypto = new Crypto(voterDataEncryptionKey); MasterPassword = Crypto.Hash(Bytes.From(masterPassword)); Logger = new Logger(this, logPrefix); Database = new VoterListDatabase(this, _dbPrefix); Manager = Address; Logger.Log("Manager initialized", Level.Info); }