- Timestamp:
- Feb 2, 2011 4:51:29 PM (13 years ago)
- Location:
- trunk/p2p
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/p2p/client.tcl
r1273 r2080 86 86 public method send {message} 87 87 public method address {} 88 89 protected method handlerType {}90 88 } 91 89 … … 101 99 set _sid "" 102 100 } else { 103 log debug " sending: $message"101 log debug "outgoing message to [address]: $message" 104 102 puts $_sid $message 105 103 } … … 116 114 return $_addr 117 115 } 118 119 # ----------------------------------------------------------------------120 # USAGE: handlerType121 #122 # Returns a descriptive string describing this handler. Derived123 # classes override this method to provide their own string. Used124 # for debug messages.125 # ----------------------------------------------------------------------126 itcl::body Client::handlerType {} {127 return "client"128 } -
trunk/p2p/foreman.tcl
r1273 r2080 119 119 120 120 if {"" != [statedata authoritycnx]} { 121 [statedata authoritycnx] send "identity foreman" 121 122 [statedata authoritycnx] send "workers" 122 123 } else { … … 160 161 161 162 if {"" != [statedata workercnx]} { 163 [statedata workercnx] send "identity foreman" 162 164 [statedata workercnx] send "solicit -job [expr {rand()}]" 163 165 } else { -
trunk/p2p/handler.tcl
r1273 r2080 59 59 protected method finalize {protocol} 60 60 protected method dropped {cid} 61 protected method handlerType {}62 61 } 63 62 … … 196 195 append mesg "exception: $result" 197 196 } 198 log debug " [handlerType]message from [connectionName $cid]: [string trimright $request \n] $mesg"197 log debug "incoming message from [connectionName $cid]: [string trimright $request \n] $mesg" 199 198 } 200 199 } … … 237 236 catch {unset _cname($cid)} 238 237 } 239 240 # ----------------------------------------------------------------------241 # USAGE: handlerType242 #243 # Returns a descriptive string describing this handler. Derived244 # classes override this method to provide their own string. Used245 # for debug messages.246 # ----------------------------------------------------------------------247 itcl::body Handler::handlerType {} {248 return "handler"249 } -
trunk/p2p/protocols.tcl
r1273 r2080 81 81 $obj protocol $name 82 82 $obj define $name exception {message} { 83 log error "ERROR from client: $message" 83 variable cid 84 variable handler 85 log error "ERROR from client [$handler connectionName $cid]: $message" 86 } 87 $obj define $name identity {name} { 88 variable cid 89 variable handler 90 $handler connectionName $cid $name 91 return "" 84 92 } 85 93 -
trunk/p2p/server.tcl
r1273 r2080 106 106 107 107 protected method dropped {cid} 108 protected method handlerType {}109 110 108 private method accept {cid addr port} 111 109 } … … 235 233 chain $cid 236 234 } 237 238 # ----------------------------------------------------------------------239 # USAGE: handlerType240 #241 # Returns a descriptive string describing this handler. Derived242 # classes override this method to provide their own string. Used243 # for debug messages.244 # ----------------------------------------------------------------------245 itcl::body Server::handlerType {} {246 return "server"247 } -
trunk/p2p/test.tcl
r1273 r2080 142 142 # ------------------------------------------------------------------ 143 143 public proc draw {canvas time} { 144 global times 144 145 if {[info exists _shapesOnCanvas($canvas)]} { 146 set y0 5 147 if {[info exists times($time)]} { 148 $canvas create text 5 $y0 -anchor nw -text $times($time) 149 incr y0 15 150 } 151 $canvas create text 5 $y0 -anchor nw -tags entity 152 145 153 foreach obj $_shapesOnCanvas($canvas) { 146 154 if {[$obj exists $time]} { … … 222 230 pack .player.fwd -side left -padx 4 -pady 2 223 231 232 button .player.err -text "0 errors" -command {wm deiconify .errors; raise .errors} 233 pack .player.err -side right -padx 4 -pady 2 234 .player.err configure -state disabled 235 224 236 scale .player.scale -label "Frame" -orient horizontal \ 225 237 -from 0 -to 1 -showvalue 0 -command {test_frame_go 1} … … 242 254 after idle .view.traffic invoke 243 255 256 toplevel .errors 257 wm title .errors "Error Messages" 258 wm withdraw .errors 259 wm protocol .errors WM_DELETE_WINDOW {wm withdraw .errors} 260 scrollbar .errors.ysbar -orient vertical -command {.errors.info yview} 261 pack .errors.ysbar -side right -fill y 262 text .errors.info -yscrollcommand {.errors.ysbar set} -font {Courier 12} 263 pack .errors.info -expand yes -fill both 264 .errors.info tag configure timecode -foreground gray 265 .errors.info tag configure error -foreground red -font {Courier 12 bold} 266 244 267 proc test_stop {} { 245 268 global processes … … 279 302 280 303 proc test_reload {} { 281 global time0 nodes actions nodeRadius304 global time0 nodes actions times nodeRadius 282 305 283 306 array set colors { 284 307 authority blue 285 308 worker gray 309 foreman red 286 310 } 287 311 288 312 Shape::clear .diagram.network 289 313 Shape::clear .diagram.traffic 314 .errors.info configure -state normal 315 .errors.info delete 1.0 end 290 316 set tmax 0 317 set errs 0 291 318 292 319 # … … 298 325 close $fid 299 326 300 if {[regexp -- {foreman<-} $info]} { 301 # skip log file from foreman 327 set lasttime "" 328 set t0val ""; set first "" 329 set t1val ""; set last "" 330 set info [split $info \n] 331 foreach line $info { 332 if {[regexp {^([0-9]+/[0-9]+/[0-9]+ [0-9]+:[0-9]+:[0-9]+)} $line match tval]} { 333 if {"" == $t0val} { 334 set first $line 335 set t0val [expr {([clock scan $tval]-$time0)*100}] 336 } else { 337 set last $line 338 set t1val [expr {([clock scan $tval]-$time0)*100 + 99}] 339 } 340 } 341 } 342 343 if {"" == $t0val || "" == $t1val} { 344 # can't find any log statements -- skip this file! 302 345 continue 303 346 } 304 347 305 348 # get the address for this host 306 regexp {started at port ([0-9]+)} $info match port 307 if {[regexp {options [^\n]+ ip ([^ ]+)} $info match ip]} { 308 set addr $ip:$port 349 if {[regexp {started at port ([0-9]+)} $info match port]} { 350 if {[regexp {options [^\n]+ ip ([^ ]+)} $info match ip]} { 351 set addr $ip:$port 352 } else { 353 set addr 127.0.0.1:$port 354 } 355 set shape oval 356 regexp {^([0-9]+/[0-9]+/[0-9]+ [0-9]+:[0-9]+:[0-9]+) +(authority|worker)} $first match t0 type 357 } elseif {[regexp -- {foreman<-} $info]} { 358 set shape rectangle 359 set addr "foreman" 360 set type "foreman" 309 361 } else { 310 set addr 127.0.0.1:$port 311 } 312 313 set lasttime "" 314 set info [split $info \n] 315 set first [lindex $info 0] 316 regexp {^([0-9]+/[0-9]+/[0-9]+ [0-9]+:[0-9]+:[0-9]+) +(authority|worker)} $first match t0 type 317 set t0val [expr {([clock scan $t0]-$time0)*100}] 318 319 set last [lindex $info end-1] 320 regexp {^([0-9]+/[0-9]+/[0-9]+ [0-9]+:[0-9]+:[0-9]+)} $last match t1 321 set t1val [expr {([clock scan $t1]-$time0)*100 + 99}] 362 # unknown log file -- skip it 363 continue 364 } 322 365 set margin 20 323 366 set r $nodeRadius … … 337 380 foreach canv {.diagram.traffic .diagram.network} { 338 381 set s [Shape ::#auto $canv -command \ 339 [list %c create oval[expr {$x-$r}] [expr {$y-$r}] \382 [list %c create $shape [expr {$x-$r}] [expr {$y-$r}] \ 340 383 [expr {$x+$r}] [expr {$y+$r}] \ 341 384 -outline black -fill $colors($type) \ … … 359 402 puts "\nscanning $fname" 360 403 361 if {[regexp -- {foreman<-} $info]} {362 # skip log file from foreman363 continue364 }365 366 404 catch {unset started} 367 405 set peerlist(addrs) "" … … 380 418 if {$tval > $tmax} { set tmax $tval } 381 419 420 set cid "" 382 421 if {[regexp {accepted: +([^ ]+) +\((.+)\)} $mesg match addr cid]} { 383 422 append actions($tval) $mesg \n … … 386 425 387 426 } elseif {[regexp {dropped: +([^ ]+) +\((.+)\)} $mesg match addr cid] && [info exists started(connect$cid-time)]} { 427 incr tval 99 ;# end of this second 388 428 append actions($tval) $mesg \n 389 429 set from $nodes($fname) … … 399 439 unset started(connect$cid-addr) 400 440 401 } elseif {[regexp {(server|client) message from ([a-zA-Z0-9\.]+:[0-9]+) \(([a-z0-9]+)\): +(.+) => (.*)} $mesg match which addr cid cmd result]} { 402 if {![string match identity* $cmd]} { 403 append actions($tval) $mesg \n 404 set from $nodes($fname) 405 set x0 $nodes($from-x) 406 set y0 $nodes($from-y) 407 set x1 $nodes($addr-x) 408 set y1 $nodes($addr-y) 409 set w [expr {[winfo width .diagram]/2}] 410 411 set s [Shape ::#auto .diagram.traffic -command \ 412 [list %c create line [expr $x0-3] [expr $y0-3] [expr $x1-3] [expr $y1-3] -fill black -arrow first -tags transient]] 413 $s addRange $tval $tval 414 415 set s [Shape ::#auto .diagram.traffic -command \ 416 [list %c create text [expr {0.5*($x0+$x1)}] [expr {0.5*($y0+$y1)-1}] -width $w -fill black -anchor s -text $cmd -tags transient]] 417 $s addRange $tval $tval 418 419 if {"" != [string trim $result]} { 420 if {[regexp {^ok:} $result]} { 421 set color black 422 } else { 423 set color red 424 } 425 set s [Shape ::#auto .diagram.traffic -command \ 426 [list %c create line [expr $x0+3] [expr $y0+3] [expr $x1+3] [expr $y1+3] -fill $color -arrow last -tags transient]] 427 $s addRange $tval $tval 428 429 set s [Shape ::#auto .diagram.traffic -command \ 430 [list %c create text [expr {0.5*($x0+$x1)}] [expr {0.5*($y0+$y1)+1}] -width $w -fill $color -anchor n -text $result -tags transient]] 431 $s addRange $tval $tval 441 } elseif {[regexp {(incoming) message from ([^ ]+) \((sock[0-9]+)\): +(.+) => (.*)} $mesg match which addr cid cmd result] 442 || [regexp {(outgoing) message to ([^ ]+): +(.+)} $mesg match which addr cmd]} { 443 switch -- $which { 444 outgoing { 445 set from $addr 446 set to $nodes($fname) 447 } 448 incoming { 449 set from $nodes($fname) 450 set to $addr 451 # show incoming messages later in time 452 incr tval 50 432 453 } 433 454 } 455 append actions($tval) $mesg \n 456 set x0 $nodes($from-x) 457 set y0 $nodes($from-y) 458 set x1 $nodes($to-x) 459 set y1 $nodes($to-y) 460 set w [expr {[winfo width .diagram]/2}] 461 462 set s [Shape ::#auto .diagram.traffic -command \ 463 [list %c create line [expr $x0-3] [expr $y0-3] [expr $x1-3] [expr $y1-3] -fill black -arrow first -tags transient]] 464 $s addRange $tval $tval 465 466 set s [Shape ::#auto .diagram.traffic -command \ 467 [list %c create text [expr {0.5*($x0+$x1)}] [expr {0.5*($y0+$y1)-1}] -width $w -fill black -anchor s -text $cmd -tags transient]] 468 $s addRange $tval $tval 469 470 if {$which == "incoming" && "" != [string trim $result]} { 471 if {[regexp {^ok:} $result]} { 472 set color black 473 } else { 474 set color red 475 } 476 set s [Shape ::#auto .diagram.traffic -command \ 477 [list %c create line [expr $x0+3] [expr $y0+3] [expr $x1+3] [expr $y1+3] -fill $color -arrow last -tags transient]] 478 $s addRange $tval $tval 479 480 set s [Shape ::#auto .diagram.traffic -command \ 481 [list %c create text [expr {0.5*($x0+$x1)}] [expr {0.5*($y0+$y1)+1}] -width $w -fill $color -anchor n -text $result -tags transient]] 482 $s addRange $tval $tval 483 } 434 484 435 485 # no address for this client yet? then save this info 436 if {[info exists started(connect$cid-addr)] 486 if {"" != $cid 487 && [info exists started(connect$cid-addr)] 437 488 && $started(connect$cid-addr) == "?"} { 438 489 set started(connect$cid-addr) $addr … … 466 517 set peerlist(addrs) $plist 467 518 set peerlist(time) $tval 519 } elseif {[regexp {ERROR} $mesg match addr]} { 520 .errors.info insert end $time timecode $mesg error "\n" 521 incr errs 468 522 } 523 set times($tval) $time 469 524 } 470 525 } … … 497 552 %W itemconfigure $fname-cnx -fill red 498 553 %W raise $fname-cnx 554 %W itemconfigure entity -text {$nodes($fname)} 499 555 " 500 556 .diagram.traffic bind $fname <Leave> " … … 502 558 %W itemconfigure $fname-cnx -fill gray 503 559 %W raise transient 560 %W itemconfigure entity -text {} 504 561 " 505 562 … … 537 594 } 538 595 .player.scale configure -to $tmax 596 .errors.info configure -state disabled 597 if {$errs == 0} { 598 .player.err configure -state normal -text "0 errors" 599 .player.err configure -state disabled 600 } else { 601 .player.err configure -state normal -text "$errs error[expr {($errs == 1) ? {} : {s}}]" 602 } 539 603 540 604 after cancel test_visualize … … 565 629 566 630 proc test_frame_go {dir position} { 567 global actions 631 global actions times 568 632 569 633 set tmax [.player.scale cget -to] -
trunk/p2p/worker.tcl
r1273 r2080 118 118 # ------------------------------------------------------------------ 119 119 define solicit {args} { 120 log debug "SOLICIT from foreman: $args"121 120 variable cid 122 121 log debug "solicitation request from foreman: $args" … … 161 160 # ------------------------------------------------------------------ 162 161 define solicit {args} { 163 log debug "SOLICIT from peer: $args"164 162 variable cid 165 163 log debug "solicitation request from peer: $args" … … 177 175 # ------------------------------------------------------------------ 178 176 define proffer {token details} { 179 log debug "PROFFER from peer: $token $details"180 177 Solicitation::proffer $token $details 181 178 return "" … … 226 223 # ------------------------------------------------------------------ 227 224 define solicit {args} { 228 log debug "SOLICIT from peer: $args"229 225 variable cid 230 226 log debug "solicitation request from peer: $args" … … 242 238 # ------------------------------------------------------------------ 243 239 define proffer {token details} { 244 log debug "PROFFER from peer: $token $details"245 240 Solicitation::proffer $token $details 246 241 return "" … … 636 631 set mesg [list solicit -job $job -path $path -avoid "$avoid @RECIPIENTS" -token $_serial] 637 632 set _waitfor [broadcast_to_peers $mesg $avoid] 638 log debug "WAIT FOR: $_waitfor"639 633 640 634 if {$_waitfor > 0} { … … 643 637 } 644 638 } 645 log debug "TIMEOUT: $delay"646 639 set _timeout [after $delay [itcl::code $this finalize]] 647 640 } … … 656 649 append _response $details "\n" 657 650 if {[incr _waitfor -1] <= 0} { 658 log debug "ALL RESPONSES"659 651 finalize 660 652 } … … 676 668 # add details about this client to the message 677 669 append block "$myaddress -job $job -cost 1 -wonks [p2p::wonks::current]" 678 log debug "FINALIZE {$block}"679 670 680 671 # send the composite results back to the caller
Note: See TracChangeset
for help on using the changeset viewer.