(c) BigSpeed Computing Inc. - Secure private networking
'Visual Basic .NET sample of secure peer-to-peer agent
'To keep this VB.NET example simple, we are going to support
'only the default user account (Guest)
Option Strict Off
Option Explicit On
Friend Class CFoMain
Inherits System.Windows.Forms.Form
#Region "Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal Disposing As Boolean)
If Disposing Then
If Not components Is Nothing Then
components.Dispose()
End If
End If
MyBase.Dispose(Disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
Public WithEvents btnCancel As System.Windows.Forms.Button
Public WithEvents btnDisconnect As System.Windows.Forms.Button
Public WithEvents btnConnect As System.Windows.Forms.Button
Public WithEvents btnSettings As System.Windows.Forms.Button
Public WithEvents btnExit As System.Windows.Forms.Button
Public WithEvents btnIP As System.Windows.Forms.Button
Public WithEvents Frame2 As System.Windows.Forms.GroupBox
Public WithEvents txtLog As System.Windows.Forms.TextBox
Public WithEvents btnClear As System.Windows.Forms.Button
Public WithEvents Frame3 As System.Windows.Forms.GroupBox
Public WithEvents helper As System.Windows.Forms.Button
Public WithEvents btnAlert As System.Windows.Forms.Button
Public WithEvents btnChat As System.Windows.Forms.Button
Public WithEvents btnFiles As System.Windows.Forms.Button
Public WithEvents btnRemove As System.Windows.Forms.Button
Public WithEvents Frame1 As System.Windows.Forms.GroupBox
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents lvPeers As System.Windows.Forms.ListView
Friend WithEvents ColumnHeader1 As System.Windows.Forms.ColumnHeader
Friend WithEvents ColumnHeader2 As System.Windows.Forms.ColumnHeader
Friend WithEvents ColumnHeader3 As System.Windows.Forms.ColumnHeader
Friend WithEvents StatusBarPanel1 As System.Windows.Forms.StatusBarPanel
Friend WithEvents StatusBarPanel2 As System.Windows.Forms.StatusBarPanel
Friend WithEvents StatusBarPanel3 As System.Windows.Forms.StatusBarPanel
Friend WithEvents StatusBar As System.Windows.Forms.StatusBar
Friend WithEvents ColumnHeader4 As System.Windows.Forms.ColumnHeader
Friend WithEvents P2PAgent As AxbsP2PAgent.AxBSP2PAgentX
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(CFoMain))
Me.Frame2 = New System.Windows.Forms.GroupBox
Me.btnCancel = New System.Windows.Forms.Button
Me.btnDisconnect = New System.Windows.Forms.Button
Me.btnConnect = New System.Windows.Forms.Button
Me.btnSettings = New System.Windows.Forms.Button
Me.btnExit = New System.Windows.Forms.Button
Me.btnIP = New System.Windows.Forms.Button
Me.Frame3 = New System.Windows.Forms.GroupBox
Me.txtLog = New System.Windows.Forms.TextBox
Me.btnClear = New System.Windows.Forms.Button
Me.helper = New System.Windows.Forms.Button
Me.Frame1 = New System.Windows.Forms.GroupBox
Me.lvPeers = New System.Windows.Forms.ListView
Me.ColumnHeader4 = New System.Windows.Forms.ColumnHeader
Me.ColumnHeader1 = New System.Windows.Forms.ColumnHeader
Me.ColumnHeader2 = New System.Windows.Forms.ColumnHeader
Me.ColumnHeader3 = New System.Windows.Forms.ColumnHeader
Me.btnAlert = New System.Windows.Forms.Button
Me.btnChat = New System.Windows.Forms.Button
Me.btnFiles = New System.Windows.Forms.Button
Me.btnRemove = New System.Windows.Forms.Button
Me.StatusBar = New System.Windows.Forms.StatusBar
Me.StatusBarPanel1 = New System.Windows.Forms.StatusBarPanel
Me.StatusBarPanel2 = New System.Windows.Forms.StatusBarPanel
Me.StatusBarPanel3 = New System.Windows.Forms.StatusBarPanel
Me.P2PAgent = New AxbsP2PAgent.AxBSP2PAgentX
Me.Frame2.SuspendLayout()
Me.Frame3.SuspendLayout()
Me.Frame1.SuspendLayout()
CType(Me.StatusBarPanel1, System.ComponentModel.ISupportInitialize).BeginInit()
CType(Me.StatusBarPanel2, System.ComponentModel.ISupportInitialize).BeginInit()
CType(Me.StatusBarPanel3, System.ComponentModel.ISupportInitialize).BeginInit()
CType(Me.P2PAgent, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'Frame2
'
Me.Frame2.BackColor = System.Drawing.SystemColors.Control
Me.Frame2.Controls.Add(Me.btnCancel)
Me.Frame2.Controls.Add(Me.btnDisconnect)
Me.Frame2.Controls.Add(Me.btnConnect)
Me.Frame2.Controls.Add(Me.btnSettings)
Me.Frame2.Controls.Add(Me.btnExit)
Me.Frame2.Controls.Add(Me.btnIP)
Me.Frame2.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Frame2.ForeColor = System.Drawing.SystemColors.ControlText
Me.Frame2.Location = New System.Drawing.Point(8, 5)
Me.Frame2.Name = "Frame2"
Me.Frame2.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.Frame2.Size = New System.Drawing.Size(616, 51)
Me.Frame2.TabIndex = 8
Me.Frame2.TabStop = False
'
'btnCancel
'
Me.btnCancel.BackColor = System.Drawing.SystemColors.Control
Me.btnCancel.Cursor = System.Windows.Forms.Cursors.Default
Me.btnCancel.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btnCancel.ForeColor = System.Drawing.SystemColors.ControlText
Me.btnCancel.Location = New System.Drawing.Point(178, 15)
Me.btnCancel.Name = "btnCancel"
Me.btnCancel.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.btnCancel.Size = New System.Drawing.Size(84, 27)
Me.btnCancel.TabIndex = 14
Me.btnCancel.Text = "Cancel"
'
'btnDisconnect
'
Me.btnDisconnect.BackColor = System.Drawing.SystemColors.Control
Me.btnDisconnect.Cursor = System.Windows.Forms.Cursors.Default
Me.btnDisconnect.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btnDisconnect.ForeColor = System.Drawing.SystemColors.ControlText
Me.btnDisconnect.Location = New System.Drawing.Point(94, 15)
Me.btnDisconnect.Name = "btnDisconnect"
Me.btnDisconnect.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.btnDisconnect.Size = New System.Drawing.Size(84, 27)
Me.btnDisconnect.TabIndex = 13
Me.btnDisconnect.Text = "Disconnect"
'
'btnConnect
'
Me.btnConnect.BackColor = System.Drawing.SystemColors.Control
Me.btnConnect.Cursor = System.Windows.Forms.Cursors.Default
Me.btnConnect.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btnConnect.ForeColor = System.Drawing.SystemColors.ControlText
Me.btnConnect.Location = New System.Drawing.Point(9, 15)
Me.btnConnect.Name = "btnConnect"
Me.btnConnect.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.btnConnect.Size = New System.Drawing.Size(84, 27)
Me.btnConnect.TabIndex = 12
Me.btnConnect.Text = "Connect"
'
'btnSettings
'
Me.btnSettings.BackColor = System.Drawing.SystemColors.Control
Me.btnSettings.Cursor = System.Windows.Forms.Cursors.Default
Me.btnSettings.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btnSettings.ForeColor = System.Drawing.SystemColors.ControlText
Me.btnSettings.Location = New System.Drawing.Point(266, 15)
Me.btnSettings.Name = "btnSettings"
Me.btnSettings.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.btnSettings.Size = New System.Drawing.Size(84, 27)
Me.btnSettings.TabIndex = 11
Me.btnSettings.Text = "Settings"
'
'btnExit
'
Me.btnExit.BackColor = System.Drawing.SystemColors.Control
Me.btnExit.Cursor = System.Windows.Forms.Cursors.Default
Me.btnExit.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btnExit.ForeColor = System.Drawing.SystemColors.ControlText
Me.btnExit.Location = New System.Drawing.Point(434, 15)
Me.btnExit.Name = "btnExit"
Me.btnExit.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.btnExit.Size = New System.Drawing.Size(84, 27)
Me.btnExit.TabIndex = 10
Me.btnExit.Text = "Exit"
'
'btnIP
'
Me.btnIP.BackColor = System.Drawing.SystemColors.Control
Me.btnIP.Cursor = System.Windows.Forms.Cursors.Default
Me.btnIP.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btnIP.ForeColor = System.Drawing.SystemColors.ControlText
Me.btnIP.Location = New System.Drawing.Point(350, 15)
Me.btnIP.Name = "btnIP"
Me.btnIP.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.btnIP.Size = New System.Drawing.Size(84, 27)
Me.btnIP.TabIndex = 9
Me.btnIP.Text = "My IP ?"
'
'Frame3
'
Me.Frame3.BackColor = System.Drawing.SystemColors.Control
Me.Frame3.Controls.Add(Me.txtLog)
Me.Frame3.Controls.Add(Me.btnClear)
Me.Frame3.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Frame3.ForeColor = System.Drawing.SystemColors.ControlText
Me.Frame3.Location = New System.Drawing.Point(8, 265)
Me.Frame3.Name = "Frame3"
Me.Frame3.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.Frame3.Size = New System.Drawing.Size(620, 187)
Me.Frame3.TabIndex = 5
Me.Frame3.TabStop = False
Me.Frame3.Text = "Log"
'
'txtLog
'
Me.txtLog.AcceptsReturn = True
Me.txtLog.AutoSize = False
Me.txtLog.BackColor = System.Drawing.SystemColors.Window
Me.txtLog.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.txtLog.CausesValidation = False
Me.txtLog.Cursor = System.Windows.Forms.Cursors.IBeam
Me.txtLog.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.txtLog.ForeColor = System.Drawing.SystemColors.WindowText
Me.txtLog.Location = New System.Drawing.Point(8, 20)
Me.txtLog.MaxLength = 0
Me.txtLog.Multiline = True
Me.txtLog.Name = "txtLog"
Me.txtLog.ReadOnly = True
Me.txtLog.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.txtLog.ScrollBars = System.Windows.Forms.ScrollBars.Both
Me.txtLog.Size = New System.Drawing.Size(600, 128)
Me.txtLog.TabIndex = 7
Me.txtLog.Text = ""
'
'btnClear
'
Me.btnClear.BackColor = System.Drawing.SystemColors.Control
Me.btnClear.Cursor = System.Windows.Forms.Cursors.Default
Me.btnClear.Enabled = False
Me.btnClear.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btnClear.ForeColor = System.Drawing.SystemColors.ControlText
Me.btnClear.Location = New System.Drawing.Point(8, 153)
Me.btnClear.Name = "btnClear"
Me.btnClear.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.btnClear.Size = New System.Drawing.Size(87, 27)
Me.btnClear.TabIndex = 6
Me.btnClear.Text = "Clear"
'
'helper
'
Me.helper.BackColor = System.Drawing.SystemColors.Control
Me.helper.Cursor = System.Windows.Forms.Cursors.Default
Me.helper.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.helper.ForeColor = System.Drawing.SystemColors.ControlText
Me.helper.Location = New System.Drawing.Point(-152, 462)
Me.helper.Name = "helper"
Me.helper.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.helper.Size = New System.Drawing.Size(119, 21)
Me.helper.TabIndex = 2
Me.helper.Text = "Command1"
'
'Frame1
'
Me.Frame1.BackColor = System.Drawing.SystemColors.Control
Me.Frame1.Controls.Add(Me.lvPeers)
Me.Frame1.Controls.Add(Me.btnAlert)
Me.Frame1.Controls.Add(Me.btnChat)
Me.Frame1.Controls.Add(Me.btnFiles)
Me.Frame1.Controls.Add(Me.btnRemove)
Me.Frame1.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Frame1.ForeColor = System.Drawing.SystemColors.ControlText
Me.Frame1.Location = New System.Drawing.Point(8, 69)
Me.Frame1.Name = "Frame1"
Me.Frame1.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.Frame1.Size = New System.Drawing.Size(618, 176)
Me.Frame1.TabIndex = 0
Me.Frame1.TabStop = False
Me.Frame1.Text = "Peers"
'
'lvPeers
'
Me.lvPeers.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.ColumnHeader4, Me.ColumnHeader1, Me.ColumnHeader2, Me.ColumnHeader3})
Me.lvPeers.FullRowSelect = True
Me.lvPeers.HideSelection = False
Me.lvPeers.Location = New System.Drawing.Point(8, 16)
Me.lvPeers.MultiSelect = False
Me.lvPeers.Name = "lvPeers"
Me.lvPeers.Size = New System.Drawing.Size(599, 121)
Me.lvPeers.TabIndex = 20
Me.lvPeers.View = System.Windows.Forms.View.Details
'
'ColumnHeader4
'
Me.ColumnHeader4.Text = "Name"
Me.ColumnHeader4.Width = 99
'
'ColumnHeader1
'
Me.ColumnHeader1.Text = "Address"
Me.ColumnHeader1.Width = 150
'
'ColumnHeader2
'
Me.ColumnHeader2.Text = "Port"
Me.ColumnHeader2.Width = 99
'
'ColumnHeader3
'
Me.ColumnHeader3.Text = "Connected"
Me.ColumnHeader3.Width = 150
'
'btnAlert
'
Me.btnAlert.BackColor = System.Drawing.SystemColors.Control
Me.btnAlert.Cursor = System.Windows.Forms.Cursors.Default
Me.btnAlert.Enabled = False
Me.btnAlert.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btnAlert.ForeColor = System.Drawing.SystemColors.ControlText
Me.btnAlert.Location = New System.Drawing.Point(8, 144)
Me.btnAlert.Name = "btnAlert"
Me.btnAlert.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.btnAlert.Size = New System.Drawing.Size(84, 26)
Me.btnAlert.TabIndex = 18
Me.btnAlert.Text = "ALert"
'
'btnChat
'
Me.btnChat.BackColor = System.Drawing.SystemColors.Control
Me.btnChat.Cursor = System.Windows.Forms.Cursors.Default
Me.btnChat.Enabled = False
Me.btnChat.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btnChat.ForeColor = System.Drawing.SystemColors.ControlText
Me.btnChat.Location = New System.Drawing.Point(93, 144)
Me.btnChat.Name = "btnChat"
Me.btnChat.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.btnChat.Size = New System.Drawing.Size(84, 26)
Me.btnChat.TabIndex = 17
Me.btnChat.Text = "Chat"
'
'btnFiles
'
Me.btnFiles.BackColor = System.Drawing.SystemColors.Control
Me.btnFiles.Cursor = System.Windows.Forms.Cursors.Default
Me.btnFiles.Enabled = False
Me.btnFiles.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btnFiles.ForeColor = System.Drawing.SystemColors.ControlText
Me.btnFiles.Location = New System.Drawing.Point(177, 144)
Me.btnFiles.Name = "btnFiles"
Me.btnFiles.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.btnFiles.Size = New System.Drawing.Size(84, 26)
Me.btnFiles.TabIndex = 16
Me.btnFiles.Text = "Files"
'
'btnRemove
'
Me.btnRemove.BackColor = System.Drawing.SystemColors.Control
Me.btnRemove.Cursor = System.Windows.Forms.Cursors.Default
Me.btnRemove.Enabled = False
Me.btnRemove.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btnRemove.ForeColor = System.Drawing.SystemColors.ControlText
Me.btnRemove.Location = New System.Drawing.Point(267, 144)
Me.btnRemove.Name = "btnRemove"
Me.btnRemove.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.btnRemove.Size = New System.Drawing.Size(84, 26)
Me.btnRemove.TabIndex = 1
Me.btnRemove.Text = "Remove"
'
'StatusBar
'
Me.StatusBar.Location = New System.Drawing.Point(0, 468)
Me.StatusBar.Name = "StatusBar"
Me.StatusBar.Panels.AddRange(New System.Windows.Forms.StatusBarPanel() {Me.StatusBarPanel1, Me.StatusBarPanel2, Me.StatusBarPanel3})
Me.StatusBar.ShowPanels = True
Me.StatusBar.Size = New System.Drawing.Size(636, 21)
Me.StatusBar.SizingGrip = False
Me.StatusBar.TabIndex = 21
Me.StatusBar.Text = "StatusBar1"
'
'StatusBarPanel1
'
Me.StatusBarPanel1.Text = "StatusBarPanel1"
Me.StatusBarPanel1.Width = 150
'
'StatusBarPanel2
'
Me.StatusBarPanel2.Text = "StatusBarPanel2"
Me.StatusBarPanel2.Width = 150
'
'StatusBarPanel3
'
Me.StatusBarPanel3.Text = "StatusBarPanel3"
Me.StatusBarPanel3.Width = 999
'
'P2PAgent
'
Me.P2PAgent.Location = New System.Drawing.Point(111, 249)
Me.P2PAgent.Name = "P2PAgent"
Me.P2PAgent.OcxState = CType(resources.GetObject("P2PAgent.OcxState"), System.Windows.Forms.AxHost.State)
Me.P2PAgent.Size = New System.Drawing.Size(299, 24)
Me.P2PAgent.TabIndex = 22
'
'CFoMain
'
Me.AutoScale = False
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 15)
Me.BackColor = System.Drawing.SystemColors.Control
Me.ClientSize = New System.Drawing.Size(636, 489)
Me.Controls.Add(Me.P2PAgent)
Me.Controls.Add(Me.StatusBar)
Me.Controls.Add(Me.Frame2)
Me.Controls.Add(Me.Frame3)
Me.Controls.Add(Me.helper)
Me.Controls.Add(Me.Frame1)
Me.Cursor = System.Windows.Forms.Cursors.Default
Me.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
Me.Location = New System.Drawing.Point(4, 27)
Me.MaximizeBox = False
Me.MinimizeBox = False
Me.Name = "CFoMain"
Me.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "BigSpeed Peer-to-Peer Agent - VB.NET Sample"
Me.Frame2.ResumeLayout(False)
Me.Frame3.ResumeLayout(False)
Me.Frame1.ResumeLayout(False)
CType(Me.StatusBarPanel1, System.ComponentModel.ISupportInitialize).EndInit()
CType(Me.StatusBarPanel2, System.ComponentModel.ISupportInitialize).EndInit()
CType(Me.StatusBarPanel3, System.ComponentModel.ISupportInitialize).EndInit()
CType(Me.P2PAgent, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
#End Region
Public Peers As New Collection
Public ThePeer, SelPeer As CPeer
Dim foSettings As CFoSettings
Dim foConnect As CFoConnect
Dim foAlert As CFoAlert
'Add a message to the log
Private Sub LogMsg(ByVal aText As String)
Dim Line As String
If txtLog.Text > "" Then
Line = Chr(13) & Chr(10)
End If
Line = Line & "[" & Now.ToLongTimeString & "] : "
Line = Line & aText
txtLog.SelectionStart = Len(txtLog.Text)
txtLog.SelectedText = Line
End Sub
Public Function PeerFromHandle(ByVal aHandle As Long) As CPeer
Dim Pr As CPeer
For Each Pr In Peers ' Iterate through elements.
If Pr.Handle = aHandle Then
PeerFromHandle = Pr
Exit For ' Exit loop.
End If
Next
End Function
Public Function PickPeer(ByVal aHandle As Long) As Boolean
ThePeer = PeerFromHandle(aHandle)
PickPeer = Not (ThePeer Is Nothing)
End Function
Public Function SelectPeer() As Boolean
SelectPeer = False
If lvPeers.SelectedItems.Count = 0 Then Exit Function
SelPeer = lvPeers.SelectedItems(0).Tag
SelectPeer = Not (SelPeer Is Nothing)
End Function
'Initializations
Private Sub fMain_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
foSettings = New CFoSettings 'create the settings form
foSettings.foMain = Me
foConnect = New CFoConnect 'create the connection form
SetSettings()
foAlert = New CFoAlert 'create the alert form
UpdateStatus()
End Sub
'Update the button state and the status text
Private Sub UpdateStatus()
If P2PAgent.SessionOpen Then
'already connected
btnConnect.Enabled = False
btnCancel.Enabled = False
btnDisconnect.Enabled = True
StatusBar.Panels(0).Text = " Session open"
StatusBar.Panels(1).Text = " Hub: " + P2PAgent.HubAddress + ":" + Str(P2PAgent.HubPort)
If P2PAgent.Username > "" Then
StatusBar.Panels(2).Text = " User: " + P2PAgent.Username
Else
StatusBar.Panels(2).Text = " User: not signed in"
End If
Else
StatusBar.Panels(1).Text = ""
StatusBar.Panels(2).Text = ""
If P2PAgent.SessionCall Then
'now connecting
btnConnect.Enabled = False
btnCancel.Enabled = True
btnDisconnect.Enabled = False
StatusBar.Panels(0).Text = " Connecting to the hub"
Else
'not connected
btnConnect.Enabled = True
btnCancel.Enabled = False
btnDisconnect.Enabled = False
StatusBar.Panels(0).Text = " Session closed"
End If
End If
UpdateButtons()
End Sub
Private Sub UpdateButtons()
btnAlert.Enabled = lvPeers.SelectedItems.Count > 0
btnChat.Enabled = lvPeers.SelectedItems.Count > 0
btnFiles.Enabled = lvPeers.SelectedItems.Count > 0
btnRemove.Enabled = lvPeers.SelectedItems.Count > 0
End Sub
'Set the component properties
Private Sub SetSettings()
If foSettings.radSecret.Checked Then
P2PAgent.SecurityMode = 1
Else
If foSettings.radPublic.Checked Then
P2PAgent.SecurityMode = 2
Else
P2PAgent.SecurityMode = 0
End If
End If
P2PAgent.SecretKey = foSettings.txtSecret.Text
P2PAgent.PublicKey = foSettings.txtPublic.Text
P2PAgent.PrivateKey = foSettings.txtPrivate.Text
P2PAgent.Fingerprints = foSettings.txtFingerprints.Text
P2PAgent.ListeningPort = Val(foSettings.txtPort.Text)
P2PAgent.BindAddress = foSettings.txtAddr.Text
End Sub
Private Sub lvPeers_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lvPeers.SelectedIndexChanged
UpdateStatus()
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
End
End Sub
Private Sub btnIP_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnIP.Click
MsgBox(P2PAgent.LocalIPList, , "My IP address")
End Sub
Private Sub btnConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConnect.Click
If foConnect.ShowDialog <> DialogResult.OK Then Exit Sub
If Not P2PAgent.OpenSession(foConnect.txtHubAddr.Text, Val(foConnect.txtHubPort.Text), foConnect.txtUsername.Text, foConnect.txtPassword.Text) Then
MsgBox("Cannot initiate a new session: " + Str(P2PAgent.LastError))
End If
UpdateStatus()
End Sub
Private Sub btnDisconnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisconnect.Click
P2PAgent.CloseSession()
End Sub
Private Sub btnSettings_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSettings.Click
If foSettings.ShowDialog <> DialogResult.OK Then Exit Sub
SetSettings()
UpdateStatus()
End Sub
Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
If Not P2PAgent.SessionCall Then Exit Sub
P2PAgent.CloseSession()
End Sub
Private Sub btnRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRemove.Click
If Not SelectPeer() Then Exit Sub
DeletePeer(SelPeer)
End Sub
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
txtLog.Clear()
End Sub
' Agent events
'Just connected to the hub
Private Sub P2PAgent_OnSessionOpen(ByVal sender As Object, ByVal e As System.EventArgs) Handles P2PAgent.OnSessionOpen
UpdateStatus()
LogMsg("Connected to the hub " + P2PAgent.HubAddress + ":" + Str(P2PAgent.HubPort))
End Sub
'Unsuccessful connection to the hub
Private Sub P2PAgent_OnSessionRejected(ByVal sender As Object, ByVal e As System.EventArgs) Handles P2PAgent.OnSessionRejected
LogMsg("Cannot open a session to" + foConnect.txtHubAddr.Text + ":" + foConnect.txtHubPort.Text + " Error- " + ErrorText(P2PAgent.LastError))
MsgBox("Cannot open the session! Error: " + ErrorText(P2PAgent.LastError))
UpdateStatus()
End Sub
'Just disconnected from the hub
Private Sub P2PAgent_OnSessionClosed(ByVal sender As Object, ByVal e As System.EventArgs) Handles P2PAgent.OnSessionClosed
UpdateStatus()
LogMsg("Disconnected from the hub")
End Sub
'A new peer is just connected
Private Sub P2PAgent_OnPeerConnected1(ByVal sender As Object, ByVal e As AxbsP2PAgent.IBSP2PAgentXEvents_OnPeerConnectedEvent) Handles P2PAgent.OnPeerConnected
Dim Pr As New CPeer
Dim LI As ListViewItem
Dim S As String
Dim i As Long
Pr.Handle = e.aHandle
Peers.Add(Pr, Str(Pr.Handle))
Pr.Username = NiceName(P2PAgent.GetPeerName(Pr.Handle))
P2PAgent.SetIncomingBandwidth(Pr.Handle, Val(foSettings.txtIncomingBandwidth.Text))
P2PAgent.SetOutgoingBandwidth(Pr.Handle, Val(foSettings.txtOutgoingBandwidth.Text))
'create the chat form
Pr.foChat = New CFoChat
Pr.foChat.foMain = Me
Pr.foChat.Peer = Pr
Pr.foChat.Text = "Chat with " + Pr.Username
'create the files form
Pr.foFiles = New CFoFiles
Pr.foFiles.foMain = Me
Pr.foFiles.Peer = Pr
Pr.foFiles.Text = Pr.Username + "'s shared files"
LI = lvPeers.Items.Add(NiceName(P2PAgent.GetPeerName(e.aHandle))) 'Name
LI.SubItems.Add(P2PAgent.GetPeerAddress(e.aHandle)) 'Address
LI.SubItems.Add(P2PAgent.GetPeerPort(e.aHandle)) 'port
LI.SubItems.Add(Now.ToLongTimeString) 'time
LI.Tag = Pr
Pr.ListItem = LI
If lvPeers.SelectedItems.Count = 0 Then
LI.Selected = True
End If
UpdateStatus()
LogMsg("New peer at " + LI.Text + ":" + LI.SubItems(1).Text)
End Sub
Sub DeletePeer(ByVal aPeer As CPeer)
If aPeer Is Nothing Then Exit Sub
P2PAgent.RemovePeer(aPeer.Handle)
lvPeers.Items.Remove(aPeer.ListItem)
Peers.Remove(Str(aPeer.Handle))
End Sub
'A peer is just disconnected
Private Sub P2PAgent_OnPeerDisconnected1(ByVal sender As Object, ByVal e As AxbsP2PAgent.IBSP2PAgentXEvents_OnPeerDisconnectedEvent) Handles P2PAgent.OnPeerDisconnected
Dim Pr As CPeer
Pr = PeerFromHandle(e.aHandle)
If Pr Is Nothing Then Exit Sub
LogMsg("Disconnected peer " + Pr.ListItem.Text + " " + Pr.ListItem.SubItems(0).Text + ":" + Str(P2PAgent.GetPeerPort(Pr.Handle)))
DeletePeer(Pr)
End Sub
' *** Alert
Private Sub btnAlert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAlert.Click
Dim i As Long
If Not SelectPeer() Then Exit Sub
foAlert.txtMsg.Text = ""
If lvPeers.SelectedItems.Count > 0 Then
foAlert.radSingle.Text = "User " + lvPeers.SelectedItems(0).Text
foAlert.radSingle.Enabled = True
foAlert.radSingle.Checked = True
Else
foAlert.radAll.Checked = True
foAlert.radSingle.Text = "Single user"
foAlert.radSingle.Enabled = False
End If
If foAlert.ShowDialog <> DialogResult.OK Then Exit Sub
If foAlert.radSingle.Checked Then
P2PAgent.SendAlertMessage(SelPeer.Handle, foAlert.txtMsg.Text)
Else
For Each Pr As CPeer In Peers
P2PAgent.SendAlertMessage(Pr.Handle, foAlert.txtMsg.Text)
Next
End If
End Sub
'An alert message is available
Private Sub P2PAgent_OnHaveAlertMessage(ByVal sender As Object, ByVal e As AxbsP2PAgent.IBSP2PAgentXEvents_OnHaveAlertMessageEvent) Handles P2PAgent.OnHaveAlertMessage
If Not PickPeer(e.aHandle) Then Exit Sub
MsgBox(e.aText, , "Alert from " + ThePeer.Username)
End Sub
' *** Chat
Private Sub btnChat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnChat.Click
If Not SelectPeer() Then Exit Sub
ShowForm(SelPeer.foChat)
End Sub
'A chat message is available
Private Sub P2PAgent_OnHaveChatMessage1(ByVal sender As Object, ByVal e As AxbsP2PAgent.IBSP2PAgentXEvents_OnHaveChatMessageEvent) Handles P2PAgent.OnHaveChatMessage
If Not PickPeer(e.aHandle) Then Exit Sub
ThePeer.foChat.HaveChatMessage(e.aText)
End Sub
' *** List folder content
'Open the file browser
Private Sub btnFiles_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFiles.Click
If Not SelectPeer() Then Exit Sub
ShowForm(SelPeer.foFiles)
End Sub
'A request to list the folder is received
Private Sub P2PAgent_OnNeedListFolder(ByVal sender As Object, ByVal e As AxbsP2PAgent.IBSP2PAgentXEvents_OnNeedListFolderEvent) Handles P2PAgent.OnNeedListFolder
If Not PickPeer(e.aHandle) Then Exit Sub
e.aOkay = True
e.aRoot = AppPath()
LogMsg(ThePeer.Username + ": list folder " + PreSlash(e.aPath))
End Sub
'A file item is received
Private Sub P2PAgent_OnHaveFileItem(ByVal sender As Object, ByVal e As AxbsP2PAgent.IBSP2PAgentXEvents_OnHaveFileItemEvent) Handles P2PAgent.OnHaveFileItem
If Not PickPeer(e.aHandle) Then Exit Sub
ThePeer.foFiles.HaveFileItem(e.aName, e.aFolder, e.aSizeLo, e.aSizeHi, e.aTimeLo, e.aTimeHi)
End Sub
'The whole folder contents is received
Private Sub P2PAgent_OnListFolderDone(ByVal sender As Object, ByVal e As AxbsP2PAgent.IBSP2PAgentXEvents_OnListFolderDoneEvent) Handles P2PAgent.OnListFolderDone
If Not PickPeer(e.aHandle) Then Exit Sub
ThePeer.foFiles.ListFolderDone(e.aCode)
End Sub
' *** Folder creation
'A request to create a folder is received (server module)
Private Sub P2PAgent_OnNeedCreateFolder(ByVal sender As Object, ByVal e As AxbsP2PAgent.IBSP2PAgentXEvents_OnNeedCreateFolderEvent) Handles P2PAgent.OnNeedCreateFolder
If Not PickPeer(e.aHandle) Then Exit Sub
e.aOkay = True
e.aRoot = AppPath()
LogMsg(ThePeer.Username + ": create folder " + PreSlash(e.aPath))
End Sub
'The folder creation is completed (client module)
Private Sub P2PAgent_OnCreateFolderDone(ByVal sender As Object, ByVal e As AxbsP2PAgent.IBSP2PAgentXEvents_OnCreateFolderDoneEvent) Handles P2PAgent.OnCreateFolderDone
If Not PickPeer(e.aHandle) Then Exit Sub
ThePeer.foFiles.CreateFolderDone(e.aCode)
End Sub
' *** Folder renaming
'A request to rename a folder is received
Private Sub P2PAgent_OnNeedRenameFolder(ByVal sender As Object, ByVal e As AxbsP2PAgent.IBSP2PAgentXEvents_OnNeedRenameFolderEvent) Handles P2PAgent.OnNeedRenameFolder
If Not PickPeer(e.aHandle) Then Exit Sub
e.aOkay = True
e.aRoot = AppPath()
LogMsg(ThePeer.Username + ": rename folder " + PreSlash(e.aPath))
End Sub
'The folder renaming is completed (client module)
Private Sub P2PAgent_OnRenameFolderDone(ByVal sender As Object, ByVal e As AxbsP2PAgent.IBSP2PAgentXEvents_OnRenameFolderDoneEvent) Handles P2PAgent.OnRenameFolderDone
If Not PickPeer(e.aHandle) Then Exit Sub
ThePeer.foFiles.RenameFolderDone(e.aCode)
End Sub
' *** File renaming
'A request to rename a file is received (server module)
Private Sub P2PAgent_OnNeedRenameFile(ByVal sender As Object, ByVal e As AxbsP2PAgent.IBSP2PAgentXEvents_OnNeedRenameFileEvent) Handles P2PAgent.OnNeedRenameFile
If Not PickPeer(e.aHandle) Then Exit Sub
e.aOkay = True
e.aRoot = AppPath()
LogMsg(ThePeer.Username + ": rename file " + PreSlash(e.aPath))
End Sub
'The file renaming is completed (client module)
Private Sub P2PAgent_OnRenameFileDone(ByVal sender As Object, ByVal e As AxbsP2PAgent.IBSP2PAgentXEvents_OnRenameFileDoneEvent) Handles P2PAgent.OnRenameFileDone
If Not PickPeer(e.aHandle) Then Exit Sub
ThePeer.foFiles.RenameFileDone(e.aCode)
End Sub
' *** Folder deletion
'A request to delete a folder is received (server module)
Private Sub P2PAgent_OnNeedDeleteFolder(ByVal sender As Object, ByVal e As AxbsP2PAgent.IBSP2PAgentXEvents_OnNeedDeleteFolderEvent) Handles P2PAgent.OnNeedDeleteFolder
If Not PickPeer(e.aHandle) Then Exit Sub
e.aOkay = True
e.aRoot = AppPath()
LogMsg(ThePeer.Username + ": delete folder " + PreSlash(e.aPath))
End Sub
'The folder deletion is completed (client module)
Private Sub P2PAgent_OnDeleteFolderDone(ByVal sender As Object, ByVal e As AxbsP2PAgent.IBSP2PAgentXEvents_OnDeleteFolderDoneEvent) Handles P2PAgent.OnDeleteFolderDone
If Not PickPeer(e.aHandle) Then Exit Sub
ThePeer.foFiles.DeleteFolderDone(e.aCode)
End Sub
' *** File deletion
'A request to delete a file is received (server module)
Private Sub P2PAgent_OnNeedDeleteFile1(ByVal sender As Object, ByVal e As AxbsP2PAgent.IBSP2PAgentXEvents_OnNeedDeleteFileEvent) Handles P2PAgent.OnNeedDeleteFile
If Not PickPeer(e.aHandle) Then Exit Sub
e.aOkay = True
e.aRoot = AppPath()
LogMsg(ThePeer.Username + ": delete file " + PreSlash(e.aPath))
End Sub
'The file deletion is completed (client module)
Private Sub P2PAgent_OnDeleteFileDone(ByVal sender As Object, ByVal e As AxbsP2PAgent.IBSP2PAgentXEvents_OnDeleteFileDoneEvent) Handles P2PAgent.OnDeleteFileDone
If Not PickPeer(e.aHandle) Then Exit Sub
ThePeer.foFiles.DeleteFileDone(e.aCode)
End Sub
' *** Downloading
'A request to download is received (server module)
Private Sub P2PAgent_OnNeedDownload(ByVal sender As Object, ByVal e As AxbsP2PAgent.IBSP2PAgentXEvents_OnNeedDownloadEvent) Handles P2PAgent.OnNeedDownload
If Not PickPeer(e.aHandle) Then Exit Sub
e.aOkay = True
e.aRoot = AppPath()
LogMsg(ThePeer.Username + ": start downloading " + PreSlash(e.aPath))
End Sub
'The download operation is completed (server module)
Private Sub P2PAgent_OnServerDownloadDone(ByVal sender As Object, ByVal e As AxbsP2PAgent.IBSP2PAgentXEvents_OnServerDownloadDoneEvent) Handles P2PAgent.OnServerDownloadDone
If Not PickPeer(e.aHandle) Then Exit Sub
LogMsg(ThePeer.Username + ": finish downloading " + ErrorText(e.aCode))
End Sub
'New progress information is available for the download operation (client module)
Private Sub P2PAgent_OnDownloadProgress(ByVal sender As Object, ByVal e As AxbsP2PAgent.IBSP2PAgentXEvents_OnDownloadProgressEvent) Handles P2PAgent.OnDownloadProgress
If Not PickPeer(e.aHandle) Then Exit Sub
ThePeer.foFiles.DownloadProgress(e.aCountLo, e.aCountHi, e.aSizeLo, e.aSizeHi)
End Sub
'The download operation is completed (client module)
Private Sub P2PAgent_OnClientDownloadDone(ByVal sender As Object, ByVal e As AxbsP2PAgent.IBSP2PAgentXEvents_OnClientDownloadDoneEvent) Handles P2PAgent.OnClientDownloadDone
If Not PickPeer(e.aHandle) Then Exit Sub
ThePeer.foFiles.DownloadDone(e.aCode)
End Sub
' *** Uploading
'A request to upload a file is received (server module)
Private Sub P2PAgent_OnNeedUpload(ByVal sender As Object, ByVal e As AxbsP2PAgent.IBSP2PAgentXEvents_OnNeedUploadEvent) Handles P2PAgent.OnNeedUpload
If Not PickPeer(e.aHandle) Then Exit Sub
e.aOkay = True
e.aRoot = AppPath()
LogMsg(ThePeer.Username + ": start uploading " + PreSlash(e.aPath))
End Sub
'The upload operation is completed (server module)
Private Sub P2PAgent_OnServerUploadDone(ByVal sender As Object, ByVal e As AxbsP2PAgent.IBSP2PAgentXEvents_OnServerUploadDoneEvent) Handles P2PAgent.OnServerUploadDone
If Not PickPeer(e.aHandle) Then Exit Sub
LogMsg(ThePeer.Username + ": finish uploading " + ErrorText(e.aCode))
End Sub
'New progress information is available for the upload operation (client module)
Private Sub P2PAgent_OnUploadProgress1(ByVal sender As Object, ByVal e As AxbsP2PAgent.IBSP2PAgentXEvents_OnUploadProgressEvent) Handles P2PAgent.OnUploadProgress
If Not PickPeer(e.aHandle) Then Exit Sub
ThePeer.foFiles.UploadProgress(e.aCountLo, e.aCountHi, e.aSizeLo, e.aSizeHi)
End Sub
'The upload operation is completed (client module)
Private Sub P2PAgent_OnClientUploadDone(ByVal sender As Object, ByVal e As AxbsP2PAgent.IBSP2PAgentXEvents_OnClientUploadDoneEvent) Handles P2PAgent.OnClientUploadDone
If Not PickPeer(e.aHandle) Then Exit Sub
ThePeer.foFiles.UploadDone(e.aCode)
End Sub
' *** Zipping
'A request to zip a file is received (server module)
Private Sub P2PAgent_OnNeedZip(ByVal sender As Object, ByVal e As AxbsP2PAgent.IBSP2PAgentXEvents_OnNeedZipEvent) Handles P2PAgent.OnNeedZip
If Not PickPeer(e.aHandle) Then Exit Sub
e.aOkay = True
e.aRoot = AppPath()
LogMsg(ThePeer.Username + ": start zipping " + PreSlash(e.aPath))
End Sub
'The zip operation is completed (server module)
Private Sub P2PAgent_OnServerZipDone(ByVal sender As Object, ByVal e As AxbsP2PAgent.IBSP2PAgentXEvents_OnServerZipDoneEvent) Handles P2PAgent.OnServerZipDone
If Not PickPeer(e.aHandle) Then Exit Sub
LogMsg(ThePeer.Username + ": finish zipping " + ErrorText(e.aCode))
End Sub
'New progress information is available for the zip operation (client module)
Private Sub P2PAgent_OnZipProgress(ByVal sender As Object, ByVal e As AxbsP2PAgent.IBSP2PAgentXEvents_OnZipProgressEvent) Handles P2PAgent.OnZipProgress
If Not PickPeer(e.aHandle) Then Exit Sub
ThePeer.foFiles.ZipProgress(e.aByteCountLo, e.aByteTotalLo)
End Sub
'The zip operation is completed (client module)
Private Sub P2PAgent_OnClientZipDone(ByVal sender As Object, ByVal e As AxbsP2PAgent.IBSP2PAgentXEvents_OnClientZipDoneEvent) Handles P2PAgent.OnClientZipDone
If Not PickPeer(e.aHandle) Then Exit Sub
ThePeer.foFiles.ZipDone(e.aCode)
End Sub
' *** Unzipping
'A request to unzip a file is received
Private Sub P2PAgent_OnNeedUnzip(ByVal sender As Object, ByVal e As AxbsP2PAgent.IBSP2PAgentXEvents_OnNeedUnzipEvent) Handles P2PAgent.OnNeedUnzip
If Not PickPeer(e.aHandle) Then Exit Sub
e.aOkay = True
e.aRoot = AppPath()
LogMsg(ThePeer.Username + ": start unzipping " + PreSlash(e.aPath))
End Sub
'The unzip operation is completed (client module)
Private Sub P2PAgent_OnClientUnzipDone(ByVal sender As Object, ByVal e As AxbsP2PAgent.IBSP2PAgentXEvents_OnClientUnzipDoneEvent) Handles P2PAgent.OnClientUnzipDone
If Not PickPeer(e.aHandle) Then Exit Sub
ThePeer.foFiles.UnzipDone(e.aCode)
End Sub
'Progress information is available for the unzip operation
Private Sub P2PAgent_OnUnzipProgress(ByVal sender As Object, ByVal e As AxbsP2PAgent.IBSP2PAgentXEvents_OnUnzipProgressEvent) Handles P2PAgent.OnUnzipProgress
If Not PickPeer(e.aHandle) Then Exit Sub
ThePeer.foFiles.ZipProgress(e.aByteCountLo, e.aByteTotalLo)
End Sub
'The unzip operation is completed (server module)
Private Sub P2PAgent_OnServerUnzipDone(ByVal sender As Object, ByVal e As AxbsP2PAgent.IBSP2PAgentXEvents_OnServerUnzipDoneEvent) Handles P2PAgent.OnServerUnzipDone
If Not PickPeer(e.aHandle) Then Exit Sub
LogMsg(ThePeer.Username + ": finish unzipping " + ErrorText(e.aCode))
End Sub
End Class
(c) BigSpeed Computing Inc. - Secure private networking