// Puts a group name into an array of bytes. private static void toBytes(SpreadGroup group, byte[] buffer, int bufferIndex) { // Get the group's name. byte[] name; try { name = System.Text.Encoding.ASCII.GetBytes(group.ToString()); } catch (Exception e) { // Already checked for this exception in connect. name = new byte[0]; Console.WriteLine(e); } // Put a cap on the length. int len = name.Length; if (len > MAX_GROUP_NAME) { len = MAX_GROUP_NAME; } // Copy the name into the buffer. System.Array.Copy(name, 0, buffer, bufferIndex, len); for ( ; len < MAX_GROUP_NAME; len++) { buffer[bufferIndex + len] = 0; } }
// Constructor. internal MembershipInfo(SpreadConnection connection, SpreadMessage message, bool daemonEndianMismatch) { // Set local variables. this.serviceType = message.ServiceType; this.group = message.Sender; this.members = message.Groups; // Is this a regular membership message. if (IsRegularMembership) { // Extract the groupID. int dataIndex = 0; int[] id = new int[3]; id[0] = SpreadConnection.toInt(message.Data, dataIndex); dataIndex += 4; id[1] = SpreadConnection.toInt(message.Data, dataIndex); dataIndex += 4; id[2] = SpreadConnection.toInt(message.Data, dataIndex); dataIndex += 4; // Endian-flip? if (daemonEndianMismatch) { id[0] = SpreadConnection.flip(id[0]); id[1] = SpreadConnection.flip(id[1]); id[2] = SpreadConnection.flip(id[2]); } // Create the group ID. this.groupID = new GroupID(id[0], id[1], id[2]); // Get the number of groups. int numGroups = SpreadConnection.toInt(message.Data, dataIndex); if (daemonEndianMismatch) { numGroups = SpreadConnection.flip(numGroups); } dataIndex += 4; // Get the groups. this.groups = new SpreadGroup[numGroups]; for (int i = 0; i < numGroups; i++) { this.groups[i] = connection.toGroup(message.Data, dataIndex); dataIndex += SpreadConnection.MAX_GROUP_NAME; } } }
private void connect(string pGroup) { // Establish the spread connection. try { connection = new SpreadConnection(); connection.Connect(address, port, userName, false, true); } catch (SpreadException _ex) { T.LogCritical("There was an error connecting to the daemon: " + _ex); Environment.Exit(1); } catch (Exception _ex) { T.LogCritical("Can't find the daemon " + address + " Exception: " + _ex); Environment.Exit(1); } // start receiving thread rt = new RecThread(connection); Thread rtt = new Thread(new ThreadStart(rt.Run)); rtt.Start(); // start listener regularMessageHandler = new SpreadConnection.MessageHandler(regularMsgReceived); connection.OnRegularMessage += regularMessageHandler; membershipMessageHandler += new SpreadConnection.MessageHandler(membershipMsgReceived); connection.OnMembershipMessage += membershipMessageHandler; lock (rt) { rt.threadSuspended = true; } listening = true; T.LogStatus("Listening: " + listening); // join group group = new SpreadGroup(); group.Join(connection, pGroup); T.LogStatus("Joined: " + group + "."); }
// Get the private group name. private void ReadGroup() { // Read the length. int len; try { len = stream.ReadByte(); } catch (Exception e) { throw new SpreadException("read(): " + e); } // Check for no more data. if (len == -1) { throw new SpreadException("Connection closed during connect attempt"); } // Read the name. byte[] buffer = new byte[len]; int numRead; try { numRead = stream.Read(buffer, 0, buffer.Length); } catch (Exception e) { throw new SpreadException("read(): " + e); } // Check for not enough data. if (numRead != len) { throw new SpreadException("Connection closed during connect attempt"); } // Store the group. group = new SpreadGroup(this, System.Text.Encoding.ASCII.GetString(buffer, 0, buffer.Length)); }
public void AddGroup(string group) { SpreadGroup spreadGroup = new SpreadGroup(null, group); AddGroup(spreadGroup); }
public void AddGroup(SpreadGroup group) { groups.Add(group); }