Using DNS TXT Records for Configuring Server Nodes

Large-scale server systems are common in this age. A small computing grid can easily consist of a few hundred nodes. Configuring such a server network can be tedious and usually requires a centralized change management system. If the centralized change management system went down, configuration/updates on the nodes can be affected.

By establishing a standard in your DNS TXT records, we can embed information such as:

  • Remote upstream server's hostname
  • Listening TCP ports on this hostname
  • Available services (in the form of a bitmask) on this server

For instance, we have a node with a hostname called node123.abc.com which connects to job1.abc.com to communicate information. We can embed the upstream hostname information (job1) in the DNS TXT record for node123. We will also embed the TCP listening ports and the type of services available in job1's DNS TXT record. Now, the client software on node123 only needs to retrieve node123's DNS TXT and learns that it needs to connect job1 as its upstream server. It will then retrieve job1's DNS TXT record and learns of the listening TCP ports on job1 machine that will listen for incoming TCP connections.

Advantages

  • Resilient distribution mechanism built on top of DNS infrastructure with DNS caching and secondary DNS servers.
  • Centralized configuration node can be "hidden" behind a firewall without being exposed on the Internet.
  • Zero-configuration on the nodes as all configuration information could potentially be learnt from the DNS TXT records, so a single installation base can be utilized for all computing nodes. In fact, in theory, you will only need to configure the node's hostname and IP network information.

Disadvantages

  • Delay in changes from configuration updates to actual change implementation on the server (due to DNS cache)
  • Potential leaks in configuration information as anyone can "lookup" the DNS records.
  • Often requires significant changes in client source code to use DNS TXT records to learn about its connection configuration
  • Limited by the small data size (approx 250 bytes) in the DNS TXT record specification.

SingTel Huawei E169 3G Modem on Windows 7

I have recently upgraded my laptop from Windows Vista 32-bit to Windows 7 Home Premium. I have performed the following steps to get my Huawei E169 3G modem working in Windows 7 again.

  1. Uninstall the SingTel Broadband on Mobile software and unplug your 3G modem from your PC/laptop
  2. Download this patch from Huawei (Local Mirror), extract the setup file and run it.
  3. Reboot your PC/laptop
  4. Plug back your 3G modem. Wait for the SingTel CD drive to appear in your "My Computer"
  5. Install the SingTel Broadband on Mobile software again. Your 3G modem should be automatically be detected after the software has been installed.

PS. SingTel Broadband on Mobile web site has some firmwares and Windows 7 fixes for Huawei E169 modem. But these softwares keep giving some code 2 errors indicating that I do not have administrator permission or the data card is being used by other software on the PC/laptop. Well, in all cases, I have gotten my 3G modem working without these "upgrades". Thank goodness.

Simple iPhone Tutorial (Part 2)

In Part 1, we have created a tutorial project, initialized the main screen with 2 tabs, and have attached a custom table view for the first tab. In Part 2, we are going to add a custom form view for the second tab.

5. Adding Child View For Second Tab

The second tab view will be a form-based view. If you are familiar with Visual Basic, you may have "played" around with the VIsual Basic controls by dragging-dropping the controls on the forms and position them according to your needs.

In XCode, create new file called SecondTabViewController using the UIViewController template. We will add 3 UILabel variables.

SecondTabViewController.h

SecondTabViewController.m

Now, create a xib file called SecondTabView using the View template.

Open the SecondTabView.xib file through Interface Builder. Drag and drop a Navigation Bar Drag and drop 3 Label (it's under Library > Cocoa Touch Plugin > Input & Values) to the View object. You can create some names for these labels--I'm using Section 0 Label 0, Section 0 Label 1 and Section 1 Label 0 so that they match closely to the variable names that we are going to connect to in SecondTabViewController class later on. These names are only for reference within the Interface Builder and do not affect your XCode.

I have added another 2 more labels to indicate the section "headers". Your second tab view will look something like the screenshot below (click to enlarge).

Now, to link up all the objects in the Interface Builder.

  1. Open up the Identity Inspector. Click on File's Owner and set Class Identity to SecondTabViewController.
  2. Connect the New Referencing Outlet in View object to the view outlet in File's Owner.
  3. For each of the named labels (Section 0 Label 0, etc), connect the New Referencing Outlet in each label to their corresponding outlet in File's Owner. For example, Section 0 Label 0 connects to section0label0.

After your have done the above connections, the black window for File's Owner should look something like the following:

Now, we will add in SecondTabViewController class to MikeTeoTutorialAppDelegate.

MikeTeoTutorialAppDelegate.h

MikeTeoTutorialAppDelegate.m

app3

Build and run. You will see that both tabs are working and the second tab's view contains the labels that you have created (click to enlarge).

6. Generating Custom Table Cells

The table view in the first tab is uninterested as it only displays static information. Most iPhone applications are interactive. We shall customize our own table cells to create on/off switch controls and a slider control.

In your XCode, create a new file called OnOffTableCell from the UITableViewCell template. Add in a UILabel variable and a UISwitch variable. Within the OnOffTableCell implementation, we initialize these two variables and hard-coded their position relative to the cell boundary.

OnOffTableCell.h

OnOffTableCell.m

onofftablecell2

Now, we can create another new file called SliderTableCell from the UITableViewCell template. This class will only have an UISlider control in the cell.

SliderTableCell.h

SliderTableCell.m

slidetablecell2

Once the table cell classes have been defined, we shall proceed to use these two classes for our table in the first tab view. Import both the OnOffTableCell.h and SliderTableCell.h into the FirstTabViewController.m like this:

Modify the (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath method in FirstTabViewController.m to return OnOffTableCell instance for section 0 (first section) and SliderTableCell instance for section 1 (second section).

Build and run. Your first tab view will now look this:

As an additional "candy", open the FirstTabView.xib in your Interface Builder. Open the Attribute Inspector (Tools >Attribute Inspector). Click on the Table View object. You should see Table View style being set to Indexed. Change this to Grouped and save.

Rebuild your application. You will see that the table view in the first tab now looks like this:

So far, we have successfully attached two views to a tab control view and use custom table cells to encapsulate a slider and an on/off switch control in the first tab's table view. In the next part, we will programmatically add action handlers to the UISlider and UISwitch controls that have been used in the custom table cells to capture user interactions, and to send their values to the UILabels that have been connected in the second tab view.

EGD: Entropy Gathering Daemon Client Protocol

The protocol is inferred by reading the source code of egd version 0.9. It is a simple binary protocol which contains 4 commands. When the client connects to EGD via unix sockets or TCP sockets, the client will initiate the communication by sending the request. The format of the request is dependent upon the nature of request; the first byte of the request will be the command code (0x01 to 0x04) that will tell the service the nature of the request.

Get Entropy Level

Client sends 1-byte value of 0x00

EGD replies with a 4-byte value indicating the current size of the entropy pool in big-endian order which will indicate the number of the random data that can be read without blocking.

Read Entropy (Non-Blocking Mode)

Client sends 1-byte value of 0x01 and 1-byte value indicating the number of bytes to request from the service. Up to 255 bytes of random data can be requested.

EGD replies (without delay) with a 1-byte value indicating the number of random data that will be returned after reading this first byte.

Read Entropy (Blocking Mode)

Client sends 1-byte value of 0x02 and 1-byte value indicating the number of bytes to request from the service. Up to 255 bytes of random data can be requested.

EGD replies (possibly with delay) with the requested random data. Note that there is no 1-byte value to indicate the number of returned random data as opposed to the non-blocking read request.

Write Entropy

Client sends 1-byte value of 0x03, 2-bytes value reflecting the number of entropy bits that is being given in this request, 1-byte value reflecting the number of bytes of random data (for the entropy bits) and followed by the string of random data. So the length of request is 4+N bytes where N is the value of the 4th byte of request.

EGD does not reply to this request.

Report PID

Client sends 1-byte value of 0x04.

EGD replies with a 1-byte value reflecting the length of pid string that will follow after this byte. Note that  the pid string is not null-terminated.

That's all for this EGD client protocol. More in-depth knowledge of the workings of the EGD can be found in egd.pl. If you have some experience with Perl, the code is actually quite self-documenting. :-P

Simple iPhone Tutorial (Part 1)

The iPhone developer center provides a great library of information of developing applications on iPhone. However, it assumes that the developer has some relative experience in developing applications on Cocoa. For developers like me who have decided to give iPhone development a try for the first time, there is undoubtedly a great hurdle to leap across.

I have put together this simple howto tutorial to illustrate some of the key features which I have picked from books (books on IPhone SDK development are seriously lacking at this point in time) and online materials that exist in bits and pieces all over the Internet. The illustrated features may not be the best solutions for the problems, but I believe they are rather straightforward and easier to align with my thought process (having come from a few years of development in MFC/Visual C++).

The tutorial will show you how to:

  • Create an iPhone application from an empty application template.
  • Add a 2-tabs tab control view for your main window on your iPhone screen.
  • Create a child view for the first tab which contains a Navigation bar (I use it for the title because it looks good), and a Table view.
  • Create another child view for the second tab which is basically a form-based view designed through the Interface Builder.
  • Load these two child views dynamically from their xib files.
  • Generate table cells which contain a label, and a on/off switch or a slider control through coding
  • Adding action handlers to the on/off switch controls and slider controls in the dynamically-generated table cells.
  • Capturing the changes in the states of the on/off switches and slider controls on the first tab view and display the states on the second tab view (form-based view).

1. What You Need

  • XCode 3.1
  • iPhone SDK
  • A machine to run OS X so that it will run XCode and the iPhone emulator
  • A nice cup of coffee to de-stress yourself :-)

2. Project Setup

Start XCode. Create a new project called MikeTeoTutorial using the Window-based Application template.

Your minimal iPhone application will be created. It should look something similar to the screenshot below.

3. Main Window

If you build your iPhone application now, it will show an empty white screen.

Double-click on your MainWindow.xib. The Interface Builder will start and load the xib file. In the Interface Builder, open up the Library (it's on the Window > Library). Find the Tab Bar Controller (it's under Library > Cocoa Touch Plugin > Controllers). Drag the Tab Bar Controller to your MainWindow.xib window in the Interface Builder.

Now, go back to your XCode and add a UITabBarController object to your MikeTeoTutorialDelegate class.

MikeTeoTutorialAppDelegate.h

MikeTeoTutorialAppDelegate.m

We call window:addSubView to add the tabBarController to the main window. You can use this call to add other views as child views not only to windows but to other views as well. (UIWindow is a subclass of UIView).

Notice that the window and tabBarController variables are both declared with an IBOutlet prefix. This will indicate to the Interface Builder that it can connect to these variables.

Go back to your Interface Builder. Right-click on the Tab Bar Controller object in MainWindow.xib window. You will see a black popup window showing a list of Outlets. Left-click and drag on the circle beside the New Referencing Outlet row. A blue line will appear as you drag. Now drag this line to the Mike Teo Tutorial Application Delegate object and release the mouse button. Another black window will popup. Click on the tabBarController variable. You will see some form of association has been formed between the tabBarController variable and the Tab Bar Controller object in the xib.

After the connection is setup, the black window will look like the following:

That's how the IBOutlet mechanism works. It allows you to link objects (having the same class, of course) in the nib to the variables declared in the classes in your source codes. If you check the Window object in the Interface Builder, you will notice that it has been already connected to the Mike Teo Tutorial App Delegate. This connection has already been done for you by default when you create this project.

Build your application now and run it. You will see a 2-tab control at the bottom of your iPhone screen, and the tabs works! :-)

4. Adding Child View For First Tab

We shall now begin adding a new view for the first tab. In XCode, add a new file (File > New File) called FirstTabViewController. Choose the UIViewController template.

The view for the first tab will contain a UITableView as one of its child views. We will add a new UITableView variable to allow the Interface Builder to connect to this variable later. We will also subclass UITableViewDataSource and UITableViewDelegate so that this class can act as a data provider for the Table View that we are going to add later in this view. We will return 2 sections: first section has 2 rows while the second section will have 1 row. We will use a default UITableViewCell to show a simple label for each row.

FirstTabViewController.h

FirstTabViewController.m

Now, we will create a new xib file for the first tab. In XCode, add a new file called FirstTabView. Choose the View XIB template.

Open this FirstTabView.xib file through Interface Builder.

  1. Now drag a Navigation Bar from the Library to your View window in Interface Builder. Place it at the top of the view. The Navigation Bar is under Library > Cocoa Touch Plugin > Windows, Views & Bars.
  2. Now drag a Table View from the Library to your View window. The Table View should stretch to fill the remaining space on the window. The Table View is under Library  > Cocoa Touch Plugin > Data Views.
  3. Open the Identity Inspector (Tools > Identity Inspector). Click on the File's Owner in FirstTabView.xib window. You should see the value of NSObject being shown in the Class field. Change this to FirstTabViewController using the drop-down list.
  4. Connect the New Referencing Outlet in View to the File's Owner. You should see a view variable. Connect to this variable.
  5. Connect the New Referencing Outlet in Table View to the File's Owner. You should see the myTableView variable. Connect to this variable.
  6. For the Outlets in Table View, connect both the delegate and dataSource to File's Owner. We can do this because we have set the File's Owner to FirstTabViewController class and the FirstTabViewController class calls conforms both UITableViewDataSource and UITableViewDelgate protocols.

After these steps, you will see a layout similar to the screenshot below (click screenshot to enlarge).

Now, we are ready to add this first tab view to the MikeTeoTutorialAppDelegate files. This will initialize the FirstTabViewController with the FirstTabView xib file.

MikeTeoTutorialAppDelegate.h

MikeTeoTutorialAppDelegate.m

app2

Build and run. You will see your table for the first tab like this:

In Part 2, we shall add in the second tab view and to create more sophisticated table view cells for the first tab view through coding.