Skip to content

Commit e9cbf73

Browse files
committed
[2.090517.55] 09/05/17 at 08:53 PM | 1 updated tm modules | by DashBot
1 parent 0a28be6 commit e9cbf73

File tree

3 files changed

+27
-21
lines changed

3 files changed

+27
-21
lines changed

cluster-1.1.2.tm renamed to cluster-1.1.3.tm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ if {$::cluster::script_dir ni [::tcl::tm::path list]} {
2323

2424
package require bpacket
2525
package require unix 1.1 ; # Need this for initial OSX Support
26+
package require shortid
2627

2728
# Source our general utilities first since they
2829
# are needed for the evaluation below.
@@ -121,7 +122,7 @@ proc ::cluster::source {} {
121122
foreach file [glob -directory $protocol_directory *.tcl] {
122123
uplevel #0 [list source $file]
123124
}
124-
set utils_directory [file join [file dirname $::cluster::script_dir cluster utils]
125+
set utils_directory [file join $::cluster::script_dir cluster utils]
125126
foreach file [glob -directory $utils_directory *.tcl] {
126127
if {[string match *general.tcl $file]} { continue }
127128
uplevel #0 [list source $file]

cluster/utils/packet.tcl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
package require bpacket;
2+
13
namespace eval ::cluster {}
24
namespace eval ::cluster::packet {
35
variable total_encoded 0
Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
namespace eval ::cluster {}
2-
namespace eval ::cluster::shortid { variable i 0; variable n 1 }
1+
namespace eval ::shortid { variable i 0; variable n 1 }
32

4-
proc ::cluster::shortid::shuffle { list {max {}}} {
3+
proc ::shortid::rand {min max} {
4+
expr { int(rand() * ($max - $min + 1) + $min)}
5+
}
6+
7+
proc ::shortid::shuffle { list {max {}}} {
58
set l1 {}; set l2 {}; set l3 {}; set l4 {}
69
foreach le $list[set list {}] {
710
if {rand()<.5} {
@@ -14,39 +17,39 @@ proc ::cluster::shortid::shuffle { list {max {}}} {
1417
return [concat $l1 $l2 $l3 $l4]
1518
}
1619

17-
proc ::cluster::shortid::encode { str {type base64} } {
20+
proc ::shortid::encode { str {type base64} } {
1821
return [string map { {=} {} } [binary encode $type $str]]
1922
}
2023

21-
proc ::cluster::shortid::shuffle_string { str {max {}} } {
22-
join [shuffle [split $str {}] $max] {}
24+
proc ::shortid::shuffle_string { str {max {}} } {
25+
join [shuffle [split $str {}] $max] {}
2326
}
2427

25-
proc ::cluster::shortid::generate { {max_length 8} } {
28+
proc ::shortid::generate { {max_length 8} } {
2629

2730
set i [incr [namespace current]::i]
28-
31+
2932
lassign [shuffle [list 1 2 3 4]] 1 2 3 4
30-
33+
3134
set clicks [clock clicks]
3235
set cmds [string map { {=} {} } [binary encode base64 [join [shuffle [info commands] 20] {}]]]
3336

3437
set cl [expr { [string length $cmds] - 5 }]
35-
set c1 [::cluster::rand $1 $cl]; set c2 [::cluster::rand $3 $cl]
36-
38+
set c1 [::shortid::rand $1 $cl]; set c2 [::shortid::rand $3 $cl]
39+
3740
set uuid [string range [shuffle_string [format {%s%s%s} \
3841
[ incr i ] \
3942
[ string range $cmds $c1 [expr { $c1 + 8 }] ] \
4043
[ string range $cmds $c2 [expr { $c2 + 8 }] ]
41-
] ] $1 [expr { $1 + [expr { round ( $max_length / 2 ) }] }]]
42-
44+
] ] $1 [expr { $1 + [expr {round( $max_length / 2 )}] }]]
45+
4346
switch -- $1 {
4447
1 { set op1 [incr [namespace current]::n]${i}$::tcl_platform(os)$::tcl_platform(osVersion) }
4548
2 { set op1 $::tcl_platform(machine)${i}$::tcl_platform(user)[incr [namespace current]::n] }
4649
3 { set op1 [string range $cmds 5 30][expr { int( rand() * [info cmdcount] + 1 ) }] }
4750
4 { set op1 $cmds }
4851
}
49-
52+
5053
switch -- $2 {
5154
1 { set op2 $::tcl_platform(os)[incr [namespace current]::n][pid] }
5255
2 { set op2 [incr [namespace current]::n]$::tcl_platform(machine)$::tcl_platform(user)${i} }
@@ -55,21 +58,21 @@ proc ::cluster::shortid::generate { {max_length 8} } {
5558
}
5659

5760
lassign [shuffle [list 1 2 3 4]] 1 2 3 4
58-
61+
5962
binary scan [ format {%s%s} \
6063
[string range $op1 $1 [expr { $1 + 8 }]] [string range [encode $op2 uuencode] $2 [expr { $2 + 8 }]] \
6164
] H* h1
62-
65+
6366
binary scan [ format {%s%s} \
6467
[string range $op2 $3 [expr { $3 + 8 }]] [string range [encode $op1 uuencode] $4 [expr { $4 + 8 }]] \
6568
] h* h2
66-
67-
append uuid [string range [ shuffle_string [ format {%s%s%s%s} \
69+
70+
append uuid [string range [shuffle_string [ format {%s%s%s%s} \
6871
$h1 $i [string toupper $h2] [string range $clicks 9 14] \
6972
] ] 0 [ expr { $max_length - [string length $uuid] }]]
7073

7174
return [string range $uuid 0 [expr { $max_length - 1 }]]
72-
75+
7376
}
7477

75-
proc ::cluster::shortid { {max_length 8} } { tailcall ::cluster::shortid::generate $max_length }
78+
proc ::shortid { {max_length 8} } { tailcall ::shortid::generate $max_length }

0 commit comments

Comments
 (0)