Example #1
0
        public SpreadGroup()
        {
            // There is no connection yet.
            connection = null;

            // There is no name.
            name = null;
        }
Example #2
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;
                }
            }
        }
Example #3
0
        public void Join(SpreadConnection c, string groupName)
        {
            // Check if this group has already been joined.
            if (this.connection != null)
            {
                throw new SpreadException("Already joined.");
            }

            // Set member variables.
            this.connection = c;
            this.name       = groupName;

            // Error check the name.
            byte[] bytes;
            try {
                bytes = System.Text.Encoding.ASCII.GetBytes(name);
            }
            catch (Exception e) {
                throw new SpreadException("Encoding not supported: " + e);
            }
            for (int i = 0; i < bytes.Length; i++)
            {
                // Make sure the byte (character) is within the valid range.
                if ((bytes[i] < 36) || (bytes[i] > 126))
                {
                    throw new SpreadException("Illegal character in group name.");
                }
            }

            // Get a new message.
            SpreadMessage joinMessage = new SpreadMessage();

            // Set the group we're sending to.
            joinMessage.AddGroup(name);

            // Set the service type.
            joinMessage.ServiceType = SpreadMessage.JOIN_MESS;

            // Send the message.
            connection.Multicast(joinMessage);
        }
        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 + ".");
        }
Example #5
0
        public void Leave()
        {
            // Check if we can leave.
            if (connection == null)
            {
                throw new SpreadException("No group to leave.");
            }

            // Get a new message.
            SpreadMessage leaveMessage = new SpreadMessage();

            // Set the group we're sending to.
            leaveMessage.AddGroup(name);

            // Set the service type.
            leaveMessage.ServiceType = SpreadMessage.LEAVE_MESS;

            // Send the message.
            connection.Multicast(leaveMessage);

            // No longer connected.
            connection = null;
        }
Example #6
0
 // Package constructor.
 internal SpreadGroup(SpreadConnection connection, String name)
 {
     // Store member variables.
     this.connection = connection;
     this.name       = name;
 }
Example #7
0
 public RecThread(SpreadConnection pConn)
 {
     connection = pConn;
 }