Diff
Not logged in

Differences From Artifact [c47a7ab27d]:

To Artifact [9f9572db47]:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
..
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
..
95
96
97
98
99
100
101

102
103
104

105
106
107
108
109
110
111
...
114
115
116
117
118
119
120


121
122
123
124
125
126
127
...
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
...
313
314
315
316
317
318
319
320

321
322
323
324

325




326
327
328
329
330

331

332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
...
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378

379
380
381
382
383
384
385
386
387
...
406
407
408
409
410
411
412
413

414
415
416
417
418
419
420
421
// Copyright 2015 MaidSafe.net limited.
//
// This SAFE Network Software is licensed to you under (1) the MaidSafe.net Commercial License,
// version 1.0 or later, or (2) The General Public License (GPL), version 3, depending on which
// licence you accepted on initial access to the Software (the "Licences").
//
// By contributing code to the SAFE Network Software, or to this project generally, you agree to be
// bound by the terms of the MaidSafe Contributor Agreement, version 1.0.  This, along with the
// Licenses can be found in the root directory of this project at LICENSE, COPYING and CONTRIBUTOR.
//
// Unless required by applicable law or agreed to in writing, the SAFE Network Software distributed
// under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.
//
// Please review the Licences for the specific language governing permissions and limitations
// relating to use of the SAFE Network Software.
................................................................................
        unknown_lints, unused, unused_allocation, unused_attributes,
        unused_comparisons, unused_features, unused_parens, while_true)]
#![warn(trivial_casts, trivial_numeric_casts, unused_extern_crates, unused_import_braces,
        unused_qualifications, unused_results)]
#![allow(box_pointers, fat_ptr_transmutes, missing_copy_implementations,
         missing_debug_implementations, variant_size_differences)]

#![cfg_attr(feature="clippy", feature(plugin))]
#![cfg_attr(feature="clippy", plugin(clippy))]
#![cfg_attr(feature="clippy", deny(clippy, unicode_not_nfc, wrong_pub_self_convention,
                                   option_unwrap_used))]
#![cfg_attr(feature="clippy", allow(use_debug, doc_markdown))] // TODO: Fix doc_markdown errors.

#[macro_use]
extern crate log;
#[macro_use]
extern crate unwrap;

extern crate crossbeam;
extern crate docopt;
................................................................................
impl Bot {
    fn new(n: usize, rng: &mut XorShiftRng, account_exists: bool) -> Self {
        let mut app_h: *mut App = ptr::null_mut();
        let mut session_h: *mut SessionHandle = ptr::null_mut();

        let mut sec_0: String = rng.gen_iter::<char>().take(10).collect();
        let mut sec_1: String = rng.gen_iter::<char>().take(10).collect();


        sec_0.push_str(&n.to_string());
        sec_1.push_str(&n.to_string());


        if account_exists {
            unsafe {
                assert_eq!(log_in(sec_0.as_bytes().as_ptr(),
                                  sec_0.as_bytes().len(),
                                  sec_1.as_bytes().as_ptr(),
                                  sec_1.as_bytes().len(),
................................................................................
            }
        } else {
            unsafe {
                assert_eq!(create_account(sec_0.as_bytes().as_ptr(),
                                          sec_0.as_bytes().len(),
                                          sec_1.as_bytes().as_ptr(),
                                          sec_1.as_bytes().len(),


                                          &mut session_h),
                           0);
            }
        }

        let app_name = format!("Bot-{}", n);
        let unique_token = format!("Bot-{}", n);
................................................................................
        }

        let prefix: String = rng.gen_iter::<char>().take(10).collect();
        let email = format!("{}-Bot-{}-mail", prefix, n);

        let tx_msgs = (0..MSGS_SENT_BY_EACH_BOT)
            .map(|x| {
                let mut msg: Vec<_> = rng.gen_iter::<u8>().take(10).collect();
                msg.extend(format!("Bot-{}-msg-{}", n, x).into_bytes());
                msg
            })
            .collect();

        Bot {
            app_h: app_h,
            session_h: session_h,
            email: email,
            tx_msgs: tx_msgs,
................................................................................
    // Create accounts for 5 bots: 27 secs, 0 millis
    // Create emails for 5 bots: 0 secs, 411 millis
    // Send total of 200 emails by 5 bots: 26 secs, 415 millis
    // Read total of 200 emails by 5 bots: 6 secs, 273 millis
    // ------------------------------------------------------------------------------------
    assert_eq!(init_logging(), 0);

    let args: Args =

        Docopt::new(USAGE).and_then(|docopt| docopt.decode()).unwrap_or_else(|error| error.exit());

    let mut rng = XorShiftRng::from_seed(match args.flag_seed {
        Some(seed) => [0, 0, 0, seed],

        None => [rand::random(), rand::random(), rand::random(), rand::random()],




    });

    // ------------------------------------------------------------------------
    // Create bots
    let mut now = Instant::now();

    let bots: Vec<_> = (0..BOTS).map(|n| Bot::new(n, &mut rng, args.flag_get_only)).collect();

    let mut duration = now.elapsed();
    info!("Create accounts for {} bots: {} secs, {} millis\n",
          BOTS,
          duration.as_secs(),
          duration.subsec_nanos() / 1000000);

    if !args.flag_get_only {
        // ------------------------------------------------------------------------
        // Create email in parallel
        now = Instant::now();
        crossbeam::scope(|scope| {
            for bot in &bots {
                let _ = scope.spawn(move || bot.create_email());
            }
        });
        duration = now.elapsed();
        info!("Create emails for {} bots: {} secs, {} millis\n",
              BOTS,
              duration.as_secs(),
              duration.subsec_nanos() / 1000000);

        // ------------------------------------------------------------------------
................................................................................
        // Send emails
        now = Instant::now();
        for (i, bot) in bots.iter().enumerate() {
            let peer_handles = Mutex::new(Vec::with_capacity(BOTS - 1));
            let peer_handles_ref = &peer_handles;

            // Get peer emails in parallel
            crossbeam::scope(|scope| {
                for (j, peer_bot) in bots.iter().enumerate() {
                    if i == j {
                        continue;
                    }
                    let _ = scope.spawn(move || {
                        unwrap!(peer_handles_ref.lock())
                            .push(bot.get_peer_email_handles(&peer_bot.email))
                    });
                }
            });

            // Send each email-msg from a bot in parallel to all others
            for msg in &bot.tx_msgs {
                let guard = unwrap!(peer_handles.lock());
                crossbeam::scope(|scope| {
                    for &(ad_h, cipher_opt_h) in &*guard {
                        let _ = scope.spawn(move || bot.send_email(ad_h, cipher_opt_h, msg));

                    }
                })
            }

            let guard = unwrap!(peer_handles.lock());
            for &(ad_h, cipher_opt_h) in &*guard {
                assert_eq!(appendable_data_free(ad_h), 0);
                assert_eq!(cipher_opt_free(cipher_opt_h), 0);
            }
................................................................................
                assert_eq!(rx_emails.len(), MSGS_SENT_BY_EACH_BOT * (BOTS - 1));

                for (j, peer_bot) in bots_ref.iter().enumerate() {
                    if i == j {
                        continue;
                    }
                    for tx_msg in &peer_bot.tx_msgs {
                        let pos = unwrap!(rx_emails.iter()

                            .position(|rx_email| *rx_email == *tx_msg));
                        let _ = rx_emails.remove(pos);
                    }
                }
            });
        }
    });
    duration = now.elapsed();







|
|







 







<
<
<
<
<
<







 







>



>







 







>
>







 







|
|
|
|







 







|
>
|


|
>
|
>
>
>
>
|




>
|
>










|
<
|
<
|







 







<
|
|
|
|
|
|
|
|
<
|




<
|
|
>
|
<







 







|
>
|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
..
27
28
29
30
31
32
33






34
35
36
37
38
39
40
..
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
...
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
...
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
...
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348

349

350
351
352
353
354
355
356
357
...
358
359
360
361
362
363
364

365
366
367
368
369
370
371
372

373
374
375
376
377

378
379
380
381

382
383
384
385
386
387
388
...
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
// Copyright 2015 MaidSafe.net limited.
//
// This SAFE Network Software is licensed to you under (1) the MaidSafe.net Commercial License,
// version 1.0 or later, or (2) The General Public License (GPL), version 3, depending on which
// licence you accepted on initial access to the Software (the "Licences").
//
// By contributing code to the SAFE Network Software, or to this project generally, you agree to be
// bound by the terms of the MaidSafe Contributor Agreement.  This, along with the Licenses can be
// found in the root directory of this project at LICENSE, COPYING and CONTRIBUTOR.
//
// Unless required by applicable law or agreed to in writing, the SAFE Network Software distributed
// under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.
//
// Please review the Licences for the specific language governing permissions and limitations
// relating to use of the SAFE Network Software.
................................................................................
        unknown_lints, unused, unused_allocation, unused_attributes,
        unused_comparisons, unused_features, unused_parens, while_true)]
#![warn(trivial_casts, trivial_numeric_casts, unused_extern_crates, unused_import_braces,
        unused_qualifications, unused_results)]
#![allow(box_pointers, fat_ptr_transmutes, missing_copy_implementations,
         missing_debug_implementations, variant_size_differences)]







#[macro_use]
extern crate log;
#[macro_use]
extern crate unwrap;

extern crate crossbeam;
extern crate docopt;
................................................................................
impl Bot {
    fn new(n: usize, rng: &mut XorShiftRng, account_exists: bool) -> Self {
        let mut app_h: *mut App = ptr::null_mut();
        let mut session_h: *mut SessionHandle = ptr::null_mut();

        let mut sec_0: String = rng.gen_iter::<char>().take(10).collect();
        let mut sec_1: String = rng.gen_iter::<char>().take(10).collect();
        let mut invitation: String = rng.gen_iter::<char>().take(10).collect();

        sec_0.push_str(&n.to_string());
        sec_1.push_str(&n.to_string());
        invitation.push_str(&n.to_string());

        if account_exists {
            unsafe {
                assert_eq!(log_in(sec_0.as_bytes().as_ptr(),
                                  sec_0.as_bytes().len(),
                                  sec_1.as_bytes().as_ptr(),
                                  sec_1.as_bytes().len(),
................................................................................
            }
        } else {
            unsafe {
                assert_eq!(create_account(sec_0.as_bytes().as_ptr(),
                                          sec_0.as_bytes().len(),
                                          sec_1.as_bytes().as_ptr(),
                                          sec_1.as_bytes().len(),
                                          invitation.as_bytes().as_ptr(),
                                          invitation.as_bytes().len(),
                                          &mut session_h),
                           0);
            }
        }

        let app_name = format!("Bot-{}", n);
        let unique_token = format!("Bot-{}", n);
................................................................................
        }

        let prefix: String = rng.gen_iter::<char>().take(10).collect();
        let email = format!("{}-Bot-{}-mail", prefix, n);

        let tx_msgs = (0..MSGS_SENT_BY_EACH_BOT)
            .map(|x| {
                     let mut msg: Vec<_> = rng.gen_iter::<u8>().take(10).collect();
                     msg.extend(format!("Bot-{}-msg-{}", n, x).into_bytes());
                     msg
                 })
            .collect();

        Bot {
            app_h: app_h,
            session_h: session_h,
            email: email,
            tx_msgs: tx_msgs,
................................................................................
    // Create accounts for 5 bots: 27 secs, 0 millis
    // Create emails for 5 bots: 0 secs, 411 millis
    // Send total of 200 emails by 5 bots: 26 secs, 415 millis
    // Read total of 200 emails by 5 bots: 6 secs, 273 millis
    // ------------------------------------------------------------------------------------
    assert_eq!(init_logging(), 0);

    let args: Args = Docopt::new(USAGE)
        .and_then(|docopt| docopt.decode())
        .unwrap_or_else(|error| error.exit());

    let mut rng = XorShiftRng::from_seed(match args.flag_seed {
                                             Some(seed) => [0, 0, 0, seed],
                                             None => {
                                                 [rand::random(),
                                                  rand::random(),
                                                  rand::random(),
                                                  rand::random()]
                                             }
                                         });

    // ------------------------------------------------------------------------
    // Create bots
    let mut now = Instant::now();
    let bots: Vec<_> = (0..BOTS)
        .map(|n| Bot::new(n, &mut rng, args.flag_get_only))
        .collect();
    let mut duration = now.elapsed();
    info!("Create accounts for {} bots: {} secs, {} millis\n",
          BOTS,
          duration.as_secs(),
          duration.subsec_nanos() / 1000000);

    if !args.flag_get_only {
        // ------------------------------------------------------------------------
        // Create email in parallel
        now = Instant::now();
        crossbeam::scope(|scope| for bot in &bots {

                             let _ = scope.spawn(move || bot.create_email());

                         });
        duration = now.elapsed();
        info!("Create emails for {} bots: {} secs, {} millis\n",
              BOTS,
              duration.as_secs(),
              duration.subsec_nanos() / 1000000);

        // ------------------------------------------------------------------------
................................................................................
        // Send emails
        now = Instant::now();
        for (i, bot) in bots.iter().enumerate() {
            let peer_handles = Mutex::new(Vec::with_capacity(BOTS - 1));
            let peer_handles_ref = &peer_handles;

            // Get peer emails in parallel

            crossbeam::scope(|scope| for (j, peer_bot) in bots.iter().enumerate() {
                                 if i == j {
                                     continue;
                                 }
                                 let _ = scope.spawn(move || {
                                                         unwrap!(peer_handles_ref.lock())
                                            .push(bot.get_peer_email_handles(&peer_bot.email))
                                                     });

                             });

            // Send each email-msg from a bot in parallel to all others
            for msg in &bot.tx_msgs {
                let guard = unwrap!(peer_handles.lock());

                crossbeam::scope(|scope| for &(ad_h, cipher_opt_h) in &*guard {
                                     let job = move || bot.send_email(ad_h, cipher_opt_h, msg);
                                     let _ = scope.spawn(job);
                                 })

            }

            let guard = unwrap!(peer_handles.lock());
            for &(ad_h, cipher_opt_h) in &*guard {
                assert_eq!(appendable_data_free(ad_h), 0);
                assert_eq!(cipher_opt_free(cipher_opt_h), 0);
            }
................................................................................
                assert_eq!(rx_emails.len(), MSGS_SENT_BY_EACH_BOT * (BOTS - 1));

                for (j, peer_bot) in bots_ref.iter().enumerate() {
                    if i == j {
                        continue;
                    }
                    for tx_msg in &peer_bot.tx_msgs {
                        let pos = unwrap!(rx_emails
                                              .iter()
                                              .position(|rx_email| *rx_email == *tx_msg));
                        let _ = rx_emails.remove(pos);
                    }
                }
            });
        }
    });
    duration = now.elapsed();