Skip to content
Browse files

Merged and cleaned

  • Loading branch information...
2 parents dd123c3 + b12f06c commit c3271efd08dc2957e4d5e79d02ab532eb0a571cd davidiw@davidiw-desktop committed Jun 7, 2007
Showing with 71 additions and 50 deletions.
  1. +37 −27 CODING_STANDARD
  2. +4 −4 src/dht/Dht.cs
  3. +26 −15 src/dht/DhtOp.cs
  4. +4 −4 src/dht/TableServer.cs
View
64 CODING_STANDARD
@@ -1,34 +1,44 @@
ACIS C# Coding Convention
-
+
1. Introduction
- This guideline aims to be a note for coding in some specific cases instead of a complete reference. Also, the convention listed here doesn't necessarily comply with the recommendations from other C# convention articles.
-2. Indention
- Use 2 Spaces instead of Tabs
+ This guideline aims to be a note for coding in some specific cases instead
+ of a complete reference. Also, the convention listed here doesn't
+ necessarily comply with the recommendations from other C# convention
+ articles.
+
+2. Indention
+ Use 2 Spaces instead of Tabs
+
3. Comments
- 1. Block (multiple lines starts with /** for /*) and C Style (/* */): general descriptions and classes, methods descriptions
- 2. Single Line (//): recommended for commenting out code
- 3. Documentation: doxygen comments prefered. Use "///" to start a one line comment, /** to start a multiple line documentation containing comment.
-4. Declarations
- {place holder}
-5. Statements
- {place holder}
+ 1. Block (multiple lines starts with /** for /*) and C Style (/* */): general
+ descriptions and classes, methods descriptions
+ 2. Single Line (//): recommended for commenting out code
+ 3. Documentation: doxygen comments prefered. Use "///" to start a one line
+ comment, /** to start a multiple line documentation containing comment.
+ 4. Declarations
+ {place holder}
+ 5. Statements
+ {place holder}
+
6. Naming Conventions:
- There are four formats used:
- a. PascalCase: FirstLetterCapitalized
- b. unix: all_lower_case_with_underscores_seperating_words
- c. underscore: _unix_naming_with_a_leading_underscore
- d. capitalized: UNIX_NAMING_WITH_CAPITAL_LETTERS
- e. CamelCase: firstLetterLowerAllOthersUpper
+ There are four formats used:
+ a. PascalCase: FirstLetterCapitalized
+ b. unix: all_lower_case_with_underscores_seperating_words
+ c. underscore: _unix_naming_with_a_leading_underscore
+ d. capitalized: UNIX_NAMING_WITH_CAPITAL_LETTERS
+ e. CamelCase: firstLetterLowerAllOthersUpper
- 1. Class/Namespaces/Methods/Properties: PascalCase (following the C# standard library: http://msdn2.microsoft.com/en-us/library/x2dbyw72(VS.71).aspx ).
- 2. Local variables: unix
- 3. Const and static readonly: capitalized
- 4. Instance and class variables: underscore
- 5. Method Parameters: CamelCase
- 6. Hungarian notations (i.e. strName) is generally considered deprecated but still allowed here for some local variables.
+ 1. Class/Namespaces/Methods/Properties: PascalCase (following the C#
+ standard library:
+ http://msdn2.microsoft.com/en-us/library/x2dbyw72(VS.71).aspx ).
+ 2. Local variables: unix
+ 3. Const and static readonly: capitalized
+ 4. Instance and class variables: underscore
+ 5. Method Parameters: CamelCase
+ 6. Hungarian notations (i.e. strName) is generally considered deprecated but
+ still allowed here for some local variables.
-7. New Lines and Braces
- 1. Open brace on new line for types (classes, namespaces, structs, etc)
- 2. Open brace on the same line for methods, anonymous methods, control blocks
- 3. "else", "catch", "finally", etc on the same line of the previous close brace.
+7. New Lines and Braces
+ Braces shall start on the same line as the statement, expression,
+ declaration prior to its use.
View
8 src/dht/Dht.cs
@@ -80,7 +80,7 @@ protected class TransferState {
lock(_sync) {
if (_entry_enumerator.MoveNext()) {
Entry e = (Entry) _entry_enumerator.Current;
- TimeSpan t_span = e.EndTime - DateTime.Now;
+ TimeSpan t_span = e.EndTime - DateTime.UtcNow;
_driver_queue = new BlockingQueue();
_driver_queue.EnqueueEvent += new EventHandler(NextTransfer);
_rpc.Invoke(_t_sender, _driver_queue, "dht.Put", e.Key,
@@ -108,7 +108,7 @@ protected class TransferState {
//initiate next transfer
if (_entry_enumerator.MoveNext()) {
Entry e = (Entry) _entry_enumerator.Current;
- TimeSpan t_span = e.EndTime - DateTime.Now;
+ TimeSpan t_span = e.EndTime - DateTime.UtcNow;
_driver_queue = new BlockingQueue();
_driver_queue.EnqueueEvent += new EventHandler(NextTransfer);
_rpc.Invoke(_t_sender, _driver_queue, "dht.Put", e.Key,
@@ -447,9 +447,9 @@ protected void ConnectHandler(object contab, EventArgs eargs)
*/
public void CheckpointHandler(object node, EventArgs eargs) {
lock(_sync) {
- if (DateTime.Now > _next_checkpoint) {
+ if (DateTime.UtcNow > _next_checkpoint) {
TimeSpan interval = new TimeSpan(0,0,0,0, _CHECKPOINT_INTERVAL);
- _next_checkpoint = DateTime.Now + interval;
+ _next_checkpoint = DateTime.UtcNow + interval;
}
}
}
View
41 src/dht/DhtOp.cs
@@ -15,7 +15,7 @@ public class DhtOp {
this.dht = dht;
}
- public static readonly int delay = 1000;
+ public static readonly int DELAY = 2000;
/* Returns a password if it works or NULL if it didn't */
public string Create(byte[] key, byte[] value, string password, int ttl) {
@@ -57,12 +57,12 @@ public class DhtOp {
allQueues.AddRange(q);
tokens = new byte[this.dht.Degree][];
- DateTime start = DateTime.Now;
+ DateTime start = DateTime.UtcNow;
while(true) {
- TimeSpan ts_timeleft = DateTime.Now - start;
+ TimeSpan ts_timeleft = DateTime.UtcNow - start;
int time_diff = ts_timeleft.Milliseconds;
- int time_left = (delay - time_diff > 0) ? delay - time_diff : 0;
+ int time_left = (DELAY - time_diff > 0) ? DELAY - time_diff : 0;
int idx = BlockingQueue.Select(allQueues, time_left);
if(idx == -1) {
break;
@@ -72,9 +72,13 @@ public class DhtOp {
queueMapping.RemoveAt(idx);
idx = real_idx;
- RpcResult rpc_reply = (RpcResult) q[idx].Dequeue();
- try{
+ if(q[idx].Closed) {
+ continue;
+ }
+ try {
+ RpcResult rpc_reply = (RpcResult) q[idx].Dequeue();
ArrayList result = (ArrayList) rpc_reply.Result;
+ //Result may be corrupted
if (result == null || result.Count < 3) {
continue;
}
@@ -93,9 +97,7 @@ public class DhtOp {
}
}
}
- catch (Exception) {
- return null;
- }
+ catch (Exception) {;} // Treat this as receiving nothing
}
foreach(BlockingQueue queue in q) {
queue.Close();
@@ -144,27 +146,36 @@ public class DhtOp {
ArrayList allQueues = new ArrayList();
allQueues.AddRange(q);
- DateTime start = DateTime.Now;
+ DateTime start = DateTime.UtcNow;
while(pcount <= majority || ncount < majority) {
- TimeSpan ts_timeleft = DateTime.Now - start;
+ TimeSpan ts_timeleft = DateTime.UtcNow - start;
int time_diff = ts_timeleft.Milliseconds;
- int time_left = (delay - time_diff > 0) ? delay - time_diff : 0;
+ int time_left = (DELAY - time_diff > 0) ? DELAY - time_diff : 0;
int idx = BlockingQueue.Select(allQueues, time_left);
+ bool result = false;
if(idx == -1) {
break;
}
- RpcResult rpc_reply = (RpcResult) ((BlockingQueue) allQueues[idx]).Dequeue();
- allQueues.RemoveAt(idx);
- bool result = (bool) rpc_reply.Result;
+
+ if(!((BlockingQueue) allQueues[idx]).Closed) {
+ try {
+ RpcResult rpc_reply = (RpcResult) ((BlockingQueue) allQueues[idx]).Dequeue();
+ result = (bool) rpc_reply.Result;
+ }
+ catch(Exception) {;} // Treat this as receiving a negative
+ }
+
if(result == true) {
pcount++;
}
else {
ncount++;
}
+ allQueues.RemoveAt(idx);
}
+
if(pcount >= majority) {
rv = "SHA1:" + password;
}
View
8 src/dht/TableServer.cs
@@ -101,7 +101,7 @@ public class TableServer {
throw new Exception("Invalid password format.");
}
- DateTime create_time = DateTime.Now;
+ DateTime create_time = DateTime.UtcNow;
TimeSpan ts = new TimeSpan(0,0,ttl);
DateTime end_time = create_time + ts;
ArrayList entry_list = null;
@@ -171,7 +171,7 @@ public class TableServer {
if (!ValidatePasswordFormat(hashed_password, out hash_name, out base64_val)) {
throw new Exception("Invalid password format.");
}
- DateTime create_time = DateTime.Now;
+ DateTime create_time = DateTime.UtcNow;
TimeSpan ts = new TimeSpan(0,0,ttl);
DateTime end_time = create_time + ts;
@@ -261,7 +261,7 @@ public class TableServer {
// Have we seen this and do we have enough space for it?
if(e.Index > seen_end_idx) {
if (e.Data.Length + consumed_bytes <= maxbytes) {
- TimeSpan age = DateTime.Now - e.CreatedTime;
+ TimeSpan age = DateTime.UtcNow - e.CreatedTime;
int age_i = (int)age.TotalSeconds;
consumed_bytes += e.Data.Length;
Hashtable item = new Hashtable();
@@ -304,7 +304,7 @@ public class TableServer {
*/
protected void DeleteExpired() {
int del_count = 0;
- DateTime now = DateTime.Now;
+ DateTime now = DateTime.UtcNow;
foreach(Entry e in _expiring_entries) {
DateTime end_time = e.EndTime;
// These should be sorted so we will break once we find an end_time greater than now

0 comments on commit c3271ef

Please sign in to comment.
Something went wrong with that request. Please try again.