public void Start() { State = BootstrapState.BeforeStart; OnBeforeStarted(new BootstrapEventArgs(BootstrapState.BeforeStart)); State = BootstrapState.Started; Boot(); State = BootstrapState.Finished; OnBeforeStarted(new BootstrapEventArgs(BootstrapState.Finished)); }
public BootstrapEventArgs(BootstrapState state = BootstrapState.NotStarted) { this.State = state; }
//static void processMsg(String strFromIP, String strToIP, String strOverlayGuid, string extractedMsg, byte[] completeMsg, int offset, int size) static void processMsg(Object incomingMsg) { String strFromIP = ((IncomingMsg)incomingMsg).strFromIP; String strToIP = ((IncomingMsg)incomingMsg).strToIP; String strCallType = ((IncomingMsg)incomingMsg).strCallType; String strOverlayGuid = ((IncomingMsg)incomingMsg).strOverlayGuid; string extractedMsg = ((IncomingMsg)incomingMsg).extractedMsg; byte[] completeMsg = ((IncomingMsg)incomingMsg).completeMsg; int offset = ((IncomingMsg)incomingMsg).offset; int size = ((IncomingMsg)incomingMsg).size; if(String.Compare(strToIP, "127.0.0.1") == 0) { Console.WriteLine("Boxit::processMsg Msg for server!"); if(String.Compare(extractedMsg, "bootStrap request") == 0) { Console.WriteLine("Boxit::processMsg Msg to server: bootStrap request"); lock(bootStrapLock) { //bootStrapAllDone.WaitOne(); Console.WriteLine("Boxit::processMsg bootStrap request : inside lock"); //bootstrapState = BootstrapState.REQUEST_RECEIVED; if(strBootstrapNodes.Count == 0) { Console.WriteLine("Boxit::processMsg Empty BootstrapNodes"); //if(bootstrapState == BootstrapState.NULL_RETURNED) // bootStrapAllDone.WaitOne(); //else bootStrapAllDone.Reset(); List<Object> msgParameters = createList(strToIP, strFromIP, strCallType, strOverlayGuid); byte[] msg = {(byte)'n', (byte)'o', (byte)' ', (byte)'b', (byte)'o', (byte)'o', (byte)'t', (byte)'s', (byte)'t', (byte)'r', (byte)'a', (byte)'p', (byte)'n', (byte)'o', (byte)'d', (byte)'e'}; msgParameters.Add(Encoding.ASCII.GetString(msg)); String strCompositeMsg = createReplyMsg(msgParameters, null); //String strCompositeMsg = createMsgForAbsentOverlay(strToIP, strFromIP, strCallType, strOverlayGuid); int compositeMsgLen = strCompositeMsg.Length; byte[] compositeMsg = System.Text.Encoding.ASCII.GetBytes(strCompositeMsg); Console.WriteLine("Boxit::processMsg sending NULL back to client"); sendMsg(strFromIP, compositeMsg, 0, compositeMsgLen); bootstrapState = BootstrapState.NULL_RETURNED; bootStrapAllDone.WaitOne(); } else { Console.WriteLine("Boxit::processMsg NON Empty BootstrapNodes"); List<Object> msgParameters = createList(strToIP, strFromIP, strCallType, strOverlayGuid, strBootstrapNodes[0]); String strCompositeMsg = createReplyMsg(msgParameters, overlayInstanceGuid); //String strCompositeMsg = createMsgForSendingOverlay(strToIP, strFromIP, strCallType, strOverlayGuid, strBootstrapNodes[0], overlayInstanceGuid); int compositeMsgLen = strCompositeMsg.Length; byte[] compositeMsg = System.Text.Encoding.ASCII.GetBytes(strCompositeMsg); Console.WriteLine("Boxit::processMsg sending overlay back to client"); sendMsg(strFromIP, compositeMsg, 0, compositeMsgLen); bootstrapState = BootstrapState.OVERLAY_INSTANCE_GUID_RETURNED; } } } else if(bootstrapState == BootstrapState.NULL_RETURNED) { Console.WriteLine("Boxit::processMsg overlayInstanceGuid received from client"); overlayInstanceGuid = new Guid(extractedMsg); //lock(bootStrapLock) { strBootstrapNodes.Add(strFromIP); } bootstrapState = BootstrapState.OVERLAY_INSTANCE_GUID_RECEIVED; bootStrapAllDone.Set(); } else { Console.WriteLine("Boxit::processMsg ?????"); } } else { Console.WriteLine("Boxit::processMsg Msg for some other client"); sendMsg(strToIP, completeMsg, offset, size); } }
//static void processMsg(String strFromIP, String strToIP, String strOverlayGuid, string extractedMsg, byte[] completeMsg, int offset, int size) static void processMsg(Object incomingMsg) { String strFromIP = ((IncomingMsg)incomingMsg).strFromIP; String strToIP = ((IncomingMsg)incomingMsg).strToIP; String strCallType = ((IncomingMsg)incomingMsg).strCallType; String strOverlayGuid = ((IncomingMsg)incomingMsg).strOverlayGuid; string extractedMsg = ((IncomingMsg)incomingMsg).extractedMsg; byte[] completeMsg = ((IncomingMsg)incomingMsg).completeMsg; int offset = ((IncomingMsg)incomingMsg).offset; int size = ((IncomingMsg)incomingMsg).size; if (String.Compare(strToIP, "127.0.0.1") == 0) { Console.WriteLine("Boxit::processMsg Msg for server!"); if (String.Compare(extractedMsg, "bootStrap request") == 0) { Console.WriteLine("Boxit::processMsg Msg to server: bootStrap request"); lock (bootStrapLock) { //bootStrapAllDone.WaitOne(); Console.WriteLine("Boxit::processMsg bootStrap request : inside lock"); //bootstrapState = BootstrapState.REQUEST_RECEIVED; if (strBootstrapNodes.Count == 0) { Console.WriteLine("Boxit::processMsg Empty BootstrapNodes"); //if(bootstrapState == BootstrapState.NULL_RETURNED) // bootStrapAllDone.WaitOne(); //else bootStrapAllDone.Reset(); List <Object> msgParameters = createList(strToIP, strFromIP, strCallType, strOverlayGuid); byte[] msg = { (byte)'n', (byte)'o', (byte)' ', (byte)'b', (byte)'o', (byte)'o', (byte)'t', (byte)'s', (byte)'t', (byte)'r', (byte)'a', (byte)'p', (byte)'n', (byte)'o', (byte)'d', (byte)'e' }; msgParameters.Add(Encoding.ASCII.GetString(msg)); String strCompositeMsg = createReplyMsg(msgParameters, null); //String strCompositeMsg = createMsgForAbsentOverlay(strToIP, strFromIP, strCallType, strOverlayGuid); int compositeMsgLen = strCompositeMsg.Length; byte[] compositeMsg = System.Text.Encoding.ASCII.GetBytes(strCompositeMsg); Console.WriteLine("Boxit::processMsg sending NULL back to client"); sendMsg(strFromIP, compositeMsg, 0, compositeMsgLen); bootstrapState = BootstrapState.NULL_RETURNED; bootStrapAllDone.WaitOne(); } else { Console.WriteLine("Boxit::processMsg NON Empty BootstrapNodes"); List <Object> msgParameters = createList(strToIP, strFromIP, strCallType, strOverlayGuid, strBootstrapNodes[0]); String strCompositeMsg = createReplyMsg(msgParameters, overlayInstanceGuid); //String strCompositeMsg = createMsgForSendingOverlay(strToIP, strFromIP, strCallType, strOverlayGuid, strBootstrapNodes[0], overlayInstanceGuid); int compositeMsgLen = strCompositeMsg.Length; byte[] compositeMsg = System.Text.Encoding.ASCII.GetBytes(strCompositeMsg); Console.WriteLine("Boxit::processMsg sending overlay back to client"); sendMsg(strFromIP, compositeMsg, 0, compositeMsgLen); bootstrapState = BootstrapState.OVERLAY_INSTANCE_GUID_RETURNED; } } } else if (bootstrapState == BootstrapState.NULL_RETURNED) { Console.WriteLine("Boxit::processMsg overlayInstanceGuid received from client"); overlayInstanceGuid = new Guid(extractedMsg); //lock(bootStrapLock) { strBootstrapNodes.Add(strFromIP); } bootstrapState = BootstrapState.OVERLAY_INSTANCE_GUID_RECEIVED; bootStrapAllDone.Set(); } else { Console.WriteLine("Boxit::processMsg ?????"); } } else { Console.WriteLine("Boxit::processMsg Msg for some other client"); sendMsg(strToIP, completeMsg, offset, size); } }