Commit 41650c9b authored by Stefan van den Oord's avatar Stefan van den Oord

Fixed API changes of NetUtils

parent 4fd98488
......@@ -48,10 +48,10 @@ public class Greeter {
guard !isStarted else { return }
let ipv4 = Interface.allInterfaces().filter {
$0.getFamily() == .ipv4 && $0.getBroadcastAddress() != nil && $0.isUp() && $0.isRunning() && !$0.isLoopback()
$0.family == .ipv4 && $0.broadcastAddress != nil && $0.isUp && $0.isRunning && !$0.isLoopback
}
let ipv6 = Interface.allInterfaces().filter {
$0.getFamily() == .ipv6 && $0.supportsMulticast() && $0.isUp() && $0.isRunning() && !$0.isLoopback()
$0.family == .ipv6 && $0.supportsMulticast && $0.isUp && $0.isRunning && !$0.isLoopback
}
start(ipv4 + ipv6)
......@@ -95,17 +95,17 @@ public class Greeter {
func startReceiving(i:Interface) throws
{
let r : Receiver.AbstractReceiver!
switch i.getFamily() {
switch i.family {
case .ipv4:
r = try Greeter.Receiver.IPv4(port: ipv4BroadcastReceivingPort, interface: i, onReceiveAnnouncement: didReceiveAnnouncement, socket:socketBuilder.createSocket())
ipv4Receivers.append(r)
print("[info] [Greeter] Started receiving on IPv4 interface \(i.getName()) (\(i.getAddress()!)) on port \(ipv4BroadcastReceivingPort)")
print("[info] [Greeter] Started receiving on IPv4 interface \(i.name) (\(i.address!)) on port \(ipv4BroadcastReceivingPort)")
case .ipv6:
r = try Greeter.Receiver.IPv6(address: ipv6MulticastAddress, port: ipv6MulticastReceivingPort, interface: i, onReceiveAnnouncement: didReceiveAnnouncement, socket:socketBuilder.createSocket())
ipv6Receivers.append(r)
print("[info] [Greeter] Started receiving on IPv6 interface \(i.getName()) (\(i.getAddress()!)) on port \(ipv6MulticastReceivingPort)")
print("[info] [Greeter] Started receiving on IPv6 interface \(i.name) (\(i.address!)) on port \(ipv6MulticastReceivingPort)")
default:
throw PulseError.GreetingConstructor("Invalid interface family \(i.getFamily())")
throw PulseError.GreetingConstructor("Invalid interface family \(i.family)")
}
try r.start()
......@@ -114,13 +114,13 @@ public class Greeter {
func setSenderAddresses() {
var addresses:[Announcement.Device.Address] = []
for r:Receiver.AbstractReceiver in ipv4Receivers + ipv6Receivers {
let addressBytes = r.interface.getAddressBytes()
let addressBytes = r.interface.addressBytes
let port = r.port
if let a = addressBytes {
addresses.append(Announcement.Device.Address(ip: a, port: port/*TODO: what should this be??*/))
}
else {
print("[error] [Greeter] Could not get address bytes for receiver on interface \(r.interface.getName()) (\(r.interface.getAddress()))")
print("[error] [Greeter] Could not get address bytes for receiver on interface \(r.interface.name) (\(r.interface.address))")
}
}
for s:Sender.AbstractSender in ipv4Senders + ipv6Senders {
......@@ -138,17 +138,17 @@ public class Greeter {
func startSending(i:Interface) throws {
let s : Sender.AbstractSender!
switch i.getFamily() {
switch i.family {
case .ipv4:
s = try Greeter.Sender.IPv4(port: ipv4BroadcastSendingPort, interface: i, deviceId: deviceId, socket:socketBuilder.createSocket(), announcementInterval:self.announcementInterval)
ipv4Senders.append(s)
print("[info] [Greeter] Started sending on IPv4 interface \(i.getName()) (\(i.getAddress()!)) to port \(ipv4BroadcastSendingPort)")
print("[info] [Greeter] Started sending on IPv4 interface \(i.name) (\(i.address!)) to port \(ipv4BroadcastSendingPort)")
case.ipv6:
s = try Greeter.Sender.IPv6(address: ipv6MulticastAddress, port: ipv6MulticastReceivingPort, interface: i, deviceId: deviceId, socket:socketBuilder.createSocket(), announcementInterval:self.announcementInterval)
ipv6Senders.append(s)
print("[info] [Greeter] Started sending on IPv6 interface \(i.getName()) (\(i.getAddress()!)) to port \(ipv6MulticastReceivingPort)")
print("[info] [Greeter] Started sending on IPv6 interface \(i.name) (\(i.address!)) to port \(ipv6MulticastReceivingPort)")
default:
throw PulseError.GreetingConstructor("Invalid interface family \(i.getFamily())")
throw PulseError.GreetingConstructor("Invalid interface family \(i.family)")
}
try s.start()
......
......@@ -89,9 +89,9 @@ extension Greeter {
try super.setSocket(s)
self.socket?.setIPv6Enabled(true)
try self.socket?.bindToPort(self.port, interface: self.interface.getName())
self.socket?.setIpv6Multicast(self.interface.getName())
try self.socket?.joinMulticastGroup(self.address, onInterface: self.interface.getName())
try self.socket?.bindToPort(self.port, interface: self.interface.name)
self.socket?.setIpv6Multicast(self.interface.name)
try self.socket?.joinMulticastGroup(self.address, onInterface: self.interface.name)
}
}
......@@ -131,7 +131,7 @@ extension Greeter {
try super.setSocket(s)
self.socket?.setIPv4Enabled(true)
self.socket?.setIPv6Enabled(true)
try self.socket?.bindToPort(0, interface: self.interface.getName())
try self.socket?.bindToPort(0, interface: self.interface.name)
}
func query(deviceId:DeviceId) throws {
......
......@@ -105,8 +105,8 @@ extension Greeter
{
try super.setSocket(s)
self.socket?.setIPv6Enabled(true)
try self.socket?.bindToPort(0, interface: self.interface.getName())
self.socket?.setIpv6Multicast(self.interface.getName())
try self.socket?.bindToPort(0, interface: self.interface.name)
self.socket?.setIpv6Multicast(self.interface.name)
}
}
......@@ -114,8 +114,8 @@ extension Greeter
{
init(port:UInt16, interface:Interface, deviceId:DeviceId, socket:GCDAsyncUdpSocket? = nil, announcementInterval:NSTimeInterval = Greeter.defaultAnnouncementInterval) throws
{
precondition(interface.getBroadcastAddress() != nil, "trying to create sender for IPv4 interface that has no broadcast address")
try super.init(address: interface.getBroadcastAddress()!, port: port, interface: interface, deviceId: deviceId, socket: socket, announcementInterval:announcementInterval)
precondition(interface.broadcastAddress != nil, "trying to create sender for IPv4 interface that has no broadcast address")
try super.init(address: interface.broadcastAddress!, port: port, interface: interface, deviceId: deviceId, socket: socket, announcementInterval:announcementInterval)
}
override func setSocket(s:GCDAsyncUdpSocket) throws
......@@ -123,7 +123,7 @@ extension Greeter
try super.setSocket(s)
self.socket?.setIPv4Enabled(true)
try self.socket?.enableBroadcast(true)
try self.socket?.bindToPort(0, interface: self.interface.getName())
try self.socket?.bindToPort(0, interface: self.interface.name)
}
}
......@@ -136,7 +136,7 @@ extension Greeter
override func setSocket(s: GCDAsyncUdpSocket) throws {
try super.setSocket(s)
self.socket?.setIPv4Enabled(true)
try self.socket?.bindToPort(0, interface: self.interface.getName())
try self.socket?.bindToPort(0, interface: self.interface.name)
}
}
}
......
......@@ -408,7 +408,7 @@ class GreeterTests : QuickSpec {
it("calls delegate when receiving announcements") {
let ipv4s = Interface.allInterfaces().filter {
$0.getName() == "lo0" && $0.getFamily() == .ipv4 && $0.isUp()
$0.name == "lo0" && $0.family == .ipv4 && $0.isUp
}
expect(ipv4s.count) == 1
guard ipv4s.count > 0 else { return }
......@@ -603,7 +603,7 @@ class GreeterTests : QuickSpec {
expect(s.lastToHost) == "announce.syncthing.net"
expect(s.lastToPort) == 21026
expect(s.supportsIPv4) == true
expect(s.boundInterface) == self.ipv4Interface.getName()
expect(s.boundInterface) == self.ipv4Interface.name
}
}
......
......@@ -2,6 +2,7 @@ import Quick
import Nimble
import Pulse
import Security
import CocoaAsyncSocket
func createTestDeviceId(desc: String) -> DeviceId {
return DeviceId(cert: SecIdentity.create(numberOfBits: 512, error: nil)!.certificate!)
......
......@@ -3,7 +3,7 @@ import CocoaAsyncSocket
import NetUtils
import Pulse
@objc class GlobalDiscoveryServerStub : NSObject
@objc class GlobalDiscoveryServerStub : NSObject, GCDAsyncUdpSocketDelegate
{
static let sendTimeout:NSTimeInterval = 30
......@@ -23,7 +23,7 @@ import Pulse
self.socket = GCDAsyncUdpSocket()
self.socket?.synchronouslySetDelegate(self)
self.socket?.synchronouslySetDelegateQueue(processQueue)
switch (self.interface.getFamily()) {
switch (self.interface.family) {
case .ipv4:
self.socket?.setIPv4Enabled(true)
self.socket?.setIPv6Enabled(false)
......@@ -33,7 +33,7 @@ import Pulse
default:
return
}
try self.socket?.bindToPort(self.port, interface:self.interface.getName())
try self.socket?.bindToPort(self.port, interface:self.interface.name)
try self.socket?.beginReceiving()
}
......
......@@ -12,8 +12,8 @@ class X509CertificateTests: QuickSpec {
it("can create self signed certificate") {
let (cert, publicKey) = self.createSelfSignedCertificate()
let subj = SecCertificateCopySubjectSummary(cert)
expect("syncthing" as NSString) == subj as NSString
let subj:NSString? = SecCertificateCopySubjectSummary(cert)
expect("syncthing") == subj
let pubBlockSize = SecKeyGetBlockSize(publicKey)
expect(Int(self.numberOfBits/8)) == pubBlockSize
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment