Skip to content

Commit

Permalink
Notification Center
Browse files Browse the repository at this point in the history
  • Loading branch information
consuelita committed May 15, 2018
1 parent 242900f commit 2f3ac7d
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 127 deletions.
Binary file modified .DS_Store
Binary file not shown.
56 changes: 28 additions & 28 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
{
"object": {
"pins": [
{
"package": "Cryptor",
"repositoryURL": "https://github.com/IBM-Swift/BlueCryptor.git",
"state": {
"branch": null,
"revision": "de20ec9af166d779a08c16f05146f4b9124478d0",
"version": "0.8.27"
}
},
{
"package": "libsodium",
"repositoryURL": "https://github.com/OperatorFoundation/Clibsodium.git",
"state": {
"branch": null,
"revision": "d2e942a7a9e2920fe144fce194381243aa1018a7",
"version": "1.0.0"
}
},
{
"package": "CommonCrypto",
"repositoryURL": "https://github.com/IBM-Swift/CommonCrypto.git",
Expand All @@ -15,17 +33,8 @@
"repositoryURL": "https://github.com/krzyzanowskim/CryptoSwift.git",
"state": {
"branch": null,
"revision": "0f5c068f1689984b47a5651e2188d2e95365e403",
"version": "0.8.1"
}
},
{
"package": "Cryptor",
"repositoryURL": "https://github.com/IBM-Swift/BlueCryptor.git",
"state": {
"branch": null,
"revision": "12f9be466d1166b16da8cb2a9d549098990248d1",
"version": "0.8.25"
"revision": "526d5e91569b30857d8def9ea22ad7265b70d238",
"version": "0.9.0"
}
},
{
Expand All @@ -47,30 +56,21 @@
}
},
{
"package": "Transport",
"repositoryURL": "https://github.com/OperatorFoundation/Transport.git",
"state": {
"branch": null,
"revision": "1bfcf07f796c7a22b5862a0953182bee0aaa2634",
"version": "0.0.3"
}
},
{
"package": "libsodium",
"repositoryURL": "https://github.com/OperatorFoundation/Clibsodium.git",
"package": "swift-sodium",
"repositoryURL": "https://github.com/OperatorFoundation/swift-sodium.git",
"state": {
"branch": null,
"revision": "d2e942a7a9e2920fe144fce194381243aa1018a7",
"version": "1.0.0"
"revision": "22cdbe7088ac3c009a5aff8abc6d73b0e6b31b02",
"version": "0.5.3"
}
},
{
"package": "swift-sodium",
"repositoryURL": "https://github.com/OperatorFoundation/swift-sodium.git",
"package": "Transport",
"repositoryURL": "https://github.com/OperatorFoundation/Transport.git",
"state": {
"branch": null,
"revision": "22cdbe7088ac3c009a5aff8abc6d73b0e6b31b02",
"version": "0.5.3"
"revision": "1bfcf07f796c7a22b5862a0953182bee0aaa2634",
"version": "0.0.3"
}
}
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module ElligatorObjC {
umbrella header "/Users/brandon/Shapeshifter-Swift-Transports/.build/checkouts/Elligator.git-1685432175989269477/Sources/ElligatorObjC/include/ElligatorObjC.h"
umbrella header "/Users/Lita/Documents/Dev/Shapeshifter-Swift-Transports/.build/checkouts/Elligator.git-1685432175989269477/Sources/ElligatorObjC/include/ElligatorObjC.h"
export *
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module celligator {
umbrella "/Users/brandon/Shapeshifter-Swift-Transports/.build/checkouts/Elligator.git-1685432175989269477/Sources/celligator/include"
umbrella "/Users/Lita/Documents/Dev/Shapeshifter-Swift-Transports/.build/checkouts/Elligator.git-1685432175989269477/Sources/celligator/include"
export *
}
137 changes: 45 additions & 92 deletions Sources/Meek/MeekTCPConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

import Foundation
import NetworkExtension
import SecurityFoundation
//import SecurityFoundation
import CryptoSwift
import ShapeshifterTesting
//import ShapeshifterTesting
import Transport

func createMeekTCPConnection(provider: PacketTunnelProvider, to: URL, serverURL: URL) -> MeekTCPConnection?
Expand All @@ -25,28 +25,20 @@ func createMeekTCPConnection(provider: PacketTunnelProvider, to: URL, serverURL:
return c
}

func createMeekTCPConnection(testDate: Date) -> MeekTCPConnection?
{
let conn = MeekTCPConnection(testDate: testDate)
guard let c = conn
else
{
return nil
}

return c
}

class MeekTCPConnection: TCPConnection
{
var hasBetterPath: Bool {
get {
var hasBetterPath: Bool
{
get
{
return network.hasBetterPath
}
}

var endpoint: NWEndpoint {
get {
var endpoint: NWEndpoint
{
get
{
return network.endpoint
}
}
Expand All @@ -73,7 +65,8 @@ class MeekTCPConnection: TCPConnection
let minLength = 1
let maxLength = MemoryLayout<UInt32>.size

enum MeekError: Error {
enum MeekError: Error
{
case unknownError
case connectionError
case meekIsClosed
Expand Down Expand Up @@ -106,11 +99,13 @@ class MeekTCPConnection: TCPConnection

private var _isViable: Bool
private var _error: Error?
private var _state: NWTCPConnectionState {
didSet {
guard let callback = stateCallback else {
return
}
private var _state: NWTCPConnectionState
{
didSet
{
NotificationCenter.default.post(name: .meekConnectionState, object: _state)
guard let callback = stateCallback
else { return }

callback(_state, nil)
}
Expand All @@ -136,15 +131,6 @@ class MeekTCPConnection: TCPConnection
sessionID = generateSessionID() ?? ""
}

///Testing Only <-------------------
convenience init?(testDate: Date)
{
let provider = FakePacketTunnelProvider()
let sURL = URL(string: "http://TestServer.com")!
let fURL = URL(string: "http://TestFront.com")!
self.init(provider: provider, to: fURL, url: sURL)
}

func observeState(_ callback: @escaping (NWTCPConnectionState, Error?) -> Void) {
self.stateCallback=callback
}
Expand Down Expand Up @@ -201,52 +187,6 @@ class MeekTCPConnection: TCPConnection
readMinimumLength(length, maximumLength: length, completionHandler: completion)
}

/*
func (c *meekConn) roundTrip(sndBuf []byte) (recvBuf []byte, err error) {
var req *http.Request
var resp *http.Response

for retries := 0; retries < maxRetries; retries++ {
url := *c.args.url
host := url.Host
if c.args.front != "" {
url.Host = c.args.front
}

req, err = http.NewRequest("POST", url.String(), bytes.NewReader(sndBuf))
if err != nil {
return nil, err
}

if c.args.front != "" {
req.Host = host
}

req.Header.Set("X-Session-Id", c.sessionID)
req.Header.Set("User-Agent", "")

resp, err = c.transport.RoundTrip(req)
if err != nil {
return nil, err
}

if resp.StatusCode != http.StatusOK {
err = fmt.Errorf("status code was %d, not %d", resp.StatusCode, http.StatusOK)
if resp.StatusCode == http.StatusInternalServerError {
return
} else {
time.Sleep(retryDelay)
}
} else {
defer resp.Body.Close()
recvBuf, err = ioutil.ReadAll(io.LimitReader(resp.Body, maxPayloadLength))
return
}
}

return
}
*/
func write(_ data: Data, completionHandler completion: @escaping (Error?) -> Void)
{
guard isViable
Expand Down Expand Up @@ -501,10 +441,6 @@ class MeekTCPConnection: TCPConnection
let randomBytes = Data(bytes: randomBytesArray)

//SHA256 random bytes.
// var hash = [UInt8](repeating: 0, count: Int(CC_SHA256_DIGEST_LENGTH))
// randomBytes.withUnsafeBytes {
// _ = CC_SHA256($0, CC_LONG(randomBytes.count), &hash)
// }
let hash = randomBytes.sha256()

//Create hex from the first 16 values of the hash array.
Expand All @@ -521,13 +457,30 @@ class MeekTCPConnection: TCPConnection
}
}

// func sha256(data: Data) -> Data
// {
// var hash = [UInt8](repeating: 0, count: Int(CC_SHA256_DIGEST_LENGTH))
// data.withUnsafeBytes {
// _ = CC_SHA256($0, CC_LONG(data.count), &hash)
// }
//
// return Data(bytes: hash)
// }
// ///Testing Only <-------------------
// convenience init?(testDate: Date)
// {
// let provider = FakePacketTunnelProvider()
// let sURL = URL(string: "http://TestServer.com")!
// let fURL = URL(string: "http://TestFront.com")!
// self.init(provider: provider, to: fURL, url: sURL)
// }

//func createMeekTCPConnection(testDate: Date) -> MeekTCPConnection?
//{
// let conn = MeekTCPConnection(testDate: testDate)
// guard let c = conn
// else
// {
// return nil
// }
//
// return c
//}

}

extension Notification.Name
{
static let meekConnectionState = Notification.Name("MeekTCPConnectionState")
}
17 changes: 12 additions & 5 deletions Sources/Wisp/WispTCPConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ class WispTCPConnection: TCPConnection

private var _isViable: Bool
private var _error: Error?
private var _state: NWTCPConnectionState {
didSet {
guard let callback = stateCallback else {
return
}
private var _state: NWTCPConnectionState
{
didSet
{
NotificationCenter.default.post(name: .wispConnectionState, object: _state)
guard let callback = stateCallback
else { return }

callback(_state, nil)
}
Expand Down Expand Up @@ -215,3 +217,8 @@ class WispTCPConnection: TCPConnection
network.cancel()
}
}

extension Notification.Name
{
static let wispConnectionState = Notification.Name("WispTCPConnectionState")
}

0 comments on commit 2f3ac7d

Please sign in to comment.